2013-04-22 131 views
-1

我正在學習python,當運行這個簡單的猜測程序時,我得到一個錯誤guess = int(input('Enter an integer:'))因爲本書基於在這個版本上。提前致謝!非常簡單的Python應用程序中的輸入錯誤

number = 23 
running = True 

while running: 
    guess = int(input('Enter an integer: ')) 

if guess == number: 
    print('Congratulations') 
    running = False 
elif guess < number: 
    print('No higher!') 
else: 
    print('Little lower!') 
else: 
print('while loop is over.') 

print('done') 

錯誤:

Enter an integer: Traceback (most recent call last): 
    File "../Documents/Python Programs/while.py", line 5, in <module> 
    guess = int(input('Enter an integer: ')) 
EOFError: EOF when reading a line 
[Finished in 0.1s with exit code 1] 
+3

請修復您的縮進。你還在哪裏運行這個程序? Sublime2? – jamylak 2013-04-22 05:52:47

+2

[Python 3不能與Sublime Text 2一起使用]的可能重複(http://stackoverflow.com/questions/13059062/python-3-is-not-working-with-sublime-text-2) – jamylak 2013-04-22 05:54:40

+0

@jamylak是崇高2和哎呀,這是一個副本和浪費的錯誤,主題中的行縮進,雖然 – 2013-04-22 05:55:51

回答

1

你的縮進是錯誤的。一旦修復,程序在Python3下運行良好。

number = 23 
running = True 

while running: 
    guess = int(input('Enter an integer: ')) 

    if guess == number: 
     print('Congratulations') 
     running = False 
    elif guess < number: 
     print('No higher!') 
    else: 
     print('Little lower!') 
else: 
    print('while loop is over.') 

print('done') 
+1

其實,這不是問題。崇高的文字2不會有任何輸入。縮進是好的(注意上面的註釋) – TerryA 2013-04-22 05:59:26

+0

@gnibbler對不起,這是一個複製和粘貼錯誤到stackoverflow,這就是我的代碼看起來像^^它不是解決方案 – 2013-04-22 05:59:50

+0

@ JOG-設計,事實上,從它看來的評論你錯了。 – 2013-04-22 06:01:28

相關問題