說SECRET_NUMBER = 77.我希望該函數能夠一直提示用戶,直到猜測出祕密數字。但是,「您的猜測太低」或「您的猜測過高」無法正常工作。 如果我輸入guess_number(4),它表示猜測值太低,但如果我接下來輸入100,它仍然表示我的猜測太低。我的功能可能有什麼問題?Python:輸入函數無法按預期方式工作
def guess_number(num):
'''(int) -> NoneType
Print out whether the secret number was guessed or a hint, if the
number was not guessed. Make this prompt the user for a number until the
secret number is guessed.
>>> guess_number(50)
Your guess was too low!
'''
while num != SECRET_NUMBER:
if num < SECRET_NUMBER:
print('Your guess was too low!')
input('Guess a number: ')
elif num > SECRET_NUMBER:
print('Your guess was too high!')
input('Guess a number: ')
else:
print('You guessed it!')