使用此代码:
import random
import query
import sys
while True:
try:
number = int(input('Choose a number between 0 and 10:'))
except ValueError:
print("That is not a number.")
continue
if number > 10:
print('Your number is too large.')
continue
elif number < 0:
print('Your number is too small.')
continue
break
result = random.randint(0, 10)
print("You're number: " + str(number))
print("Our number: " + str(result))
if number == result:
print('Congratulations!')
else:
print('Close, but no cigar.')
while True:
try:
answer = query.query_yes_no('Do you wish to contunue?')
if answer == "yes":
while True:
try:
number = int(input('Choose a number between 0 and 10:'))
except ValueError:
print("That is not a number.")
continue
if number > 10:
print('Your number is too large.')
continue
elif number < 0:
print('Your number is too small.')
continue
break
print("You're number: " + str(number))
print("Our number: " + str(result))
if number == result:
print('Congratulations!')
continue
else:
print('Close, but no cigar.')
continue
elif answer == "no":
print('Goodbye.')
break
break
break
exit()
我一直在SyntaxError: unexpected EOF while parsing
。它说它在第60行。我已经尝试删除exit()和休息但这不起作用。我确信它很简单,因为我还是Python新手。任何帮助将不胜感激!
答案 0 :(得分:3)
您需要在无限except
循环中为第一个try
添加另一个while
。这就是原因,可能是语法错误。