2013-04-29 133 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