繁体   English   中英

if 语句循环和 while 循环

[英]if statement loops and while loops

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

我正在尝试创建一个循环并提供用户必须猜测的数字的线索t 完全有效,它会一直告诉我,例如:它变小了,但是当它变大时,它就停止了,程序没有发送任何东西,但是如果我得到正确的数字,它会说恭喜,而且我想让它重新启动从用户获胜并输入 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")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM