【发布时间】:2021-08-03 04:07:45
【问题描述】:
'''
import random
correct_num = random.randint(0,10)
guess = int(input('What is your guess?'))
while guess != correct_num:
if guess > correct_num:
print('Your guess is to big')
if guess < correct_num:
print('Your guess is to small')
else:
if guess == correct_num:
print('Yes! You are correct')
'''
这是我目前所拥有的,当我运行代码时,它会无限打印输出。我怎样才能让它给出一个输出并返回另一个猜测?
【问题讨论】:
-
以
guess = -1开头,这样while循环总是至少运行一次,把guess = int(input(...))放在while循环里面
标签: python loops if-statement while-loop