-1

我正在学习 python,在运行这个简单的猜测程序时,我在guess=int(input('Enter an integer: '))运行 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]
4

1 回答 1

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')
于 2013-04-22T05:56:42.537 回答