2013-04-29 136 views
0

我不断收到EOF错误。我没有看到任何理由为什么应该对我大喊大叫。我已经尝试在3.3和2.7中运行它,所以我想一定有什么问题。虽然我在Cloud 9时没有遇到任何错误,但它不会真正运行。当我使用不同的IDE时,我遇到了这个错误。读取行时出现Python EOF错误

Executing the code.... 
$python3 demo.py 
Hello! What is your name?Traceback (most recent call last): 
    File "demo.py", line 2, in 
    name = input("Hello! What is your name?") 
EOFError: EOF when reading a line 

这是我的代码。

import sys 
name = input("Hello! What is your name?") 
print("So your name is {0}? Cool!".format(name)) 
age = input("Now tell me how old you are.") 
print("So your name is {0} and you're {1} years old?".format(name, age)) 
yn = input("Y/N?") 
if yn == "y": 
    print("Okay good!") 
elif yn == "n": 
    sys.exit(0) 

任何帮助?

+0

你在运行哪个程序? – jamylak 2013-04-29 13:15:49

+2

@jamylak看起来像'$ python demo.py Aya 2013-04-29 13:27:39

回答

0

我不知道是什么问题,但也许考虑使用raw_input?

据这里的文档(http://docs.python.org/2/library/functions.html#input):

考虑使用的raw_input()函数从用户的通用输入。

+1

我认为这可能是我使用的IDE有问题。我试着在IDLE上运行它,它运行良好。对于那个很抱歉! – Xiam 2013-04-29 13:21:34

+4

他在3.3和2.7中试过,所以这显然不是解决方案 – jamylak 2013-04-29 13:21:50

+0

@jamylak没有发现。 – 2013-04-29 13:22:52

-1

使用raw_input代替input

+5

Python 3中没有'raw_input()' – 2013-04-29 13:21:40

+2

在python 3中,'input()'与'的raw_input()'。 – Forge 2016-02-27 10:31:46