number = int(input("please choose your number: "))
while number > number_to_guess:
number = int(input("Your guess is wrong it was bigger then the generated number, try again: "))
while number < number_to_guess :
number = int(input("Your guess was wrong it was smaller then the generated number, try again: "))
if number == number_to_guess:
print("Congrats you won")
restart = input("Do you want to play again? if yes type y, if not you can close the window \n")
我试图创建一个循环,并给出用户必须猜测的数字的线索,我第一次尝试if语句,当然它没有循环,我尝试了多种方法这是我能想到的最好的方法,但它并不完全有效,它会一直告诉我,例如:它变小了,但当它变大时,它就停止了,程序没有发送任何东西,但如果我得到了正确的数字,它会说恭喜,我也想让它在用户获胜并输入y后重新开始,但我完全不知道如何做到这一点
发布于 2021-04-26 04:22:54
请按此顺序尝试
number = int(input("please choose your number: "))
number_to_guess = 5
while number != number_to_guess:
if number > number_to_guess:
number = int(input("Your guess is wrong it was bigger then the generated number, try again: "))
continue
if number < number_to_guess :
number = int(input("Your guess was wrong it was smaller then the generated number, try again: "))
continue
print("Congrats you won")
restart = input("Do you want to play again? if yes type y, if not you can close the window \n")
https://stackoverflow.com/questions/67257862
复制相似问题