输入()导致“EOL同时扫描字符串文字”错误

问题描述 投票:0回答:3

目前,我想要写在Python 3.4.7块运行如果输入材料是输入。但是,当我按下回车键,显示以下错误信息:

SyntaxError: EOL while scanning string literal

一些示例代码:

answer = input("to find out your result, press enter.")
# Problem is here, I don't know what kind of sign or Python rule I'm not following
while answer == (<<Enter>>):
    print("You are the father!")
python python-3.x input syntax
3个回答
0
投票

你要期待字符串作为输入时使用raw_inputinput评估为一个python表达。


0
投票

为什么你认为while answer == (<<Enter>>)意味着在Python什么?我建议做一个Python教程,让你可以在语法的窍门。

如果我理解你想要什么,你可以删除该行:

answer = input("to find out your result, press enter.")
print("You are the father!")

input呼叫停止别的发生压,直到进入。


0
投票

我敢肯定你没有真正使用Python 3(除非你在2017年的时候,当我猜的Python 3.4.7可能被释放)。在Python 2所述的输入到input()被执行(input(prompt) = eval(raw_input(prompt))),并且当它只是一个空字符串,它会导致一个SyntaxError

Python 2.7.9 (default, Dec 10 2014, 12:28:03) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> input('Hello?')
Hello?
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 0

    ^
SyntaxError: unexpected EOF while parsing

使用raw_input()通常是你想要的。在Python 3中除去旧input()raw_input()了它的位置。

© www.soinside.com 2019 - 2024. All rights reserved.