程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了if 语句循环和 while 循环大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决if 语句循环和 while 循环?

开发过程中遇到if 语句循环和 while 循环的问题如何解决?下面主要结合日常开发的经验,给出你关于if 语句循环和 while 循环的解决方法建议,希望对你解决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")

大佬总结

以上是大佬教程为你收集整理的if 语句循环和 while 循环全部内容,希望文章能够帮你解决if 语句循环和 while 循环所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:ifwhile循环