if 语句循环和 while 循环

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")

我正在尝试创建一个循环并提供用户必须猜测的数字的线索工作它会一直告诉我例如:它更小但是当它变大时它只是停止并且程序没有发送任何东西但是如果我正确地得到了号码它会说恭喜,我也想让它从在用户获胜并输入 y 后开始,但我完全不知道该怎么做

德谢弗

按这个顺序试试

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")

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章