非常简单的Python应用程序中的输入错误

时间:2013-04-22 05:51:44

标签: python python-3.x

我正在学习python,在运行这个简单的猜测程序时,我在 guess = int(输入('输入一个整数:'))中得到一个错误运行Python 3因为本书是基于这个版。提前谢谢!

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]

1 个答案:

答案 0 :(得分: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')
相关问题