如何使程序运行几次猜测是错误的? [英] How do I get the program to run several times of the guess is wrong?

查看:62
本文介绍了如何使程序运行几次猜测是错误的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

from random import*
SecretNumber=randint(0,12)
Guess=int(input("Please enter Guess: "))

NumberofGuesses=0



   
        
while Guess != SecretNumber:
            NumberofGuesses=NumberofGuesses+1

      
            if Guess>SecretNumber:
               print("Please insert a smaller number")
               break
               

            if Guess<SecretNumber:
                print("Please insert a bigger number")
                break
                
                
            
             
                
               
               
              


print("Number of Guesses: {0}".format(NumberofGuesses))





< b>我尝试了什么:



我尝试使用While循环,但我不知道为什么它不起作用



What I have tried:

I tried using the While loop but I dont know why it isnt working

推荐答案

B.因为它没有修改Guess。不是很明显吗?你必须在每次迭代中输入猜测。实际上,添加一些条件可以立即在用户请求中打破循环。 :-)



-SA
Because it does nothing to modify the Guess. Isn't it obvious? You have to input guess in each iteration. Practically, it's useful to add some condition to break the loop immediately on the user request. :-)

—SA


这篇关于如何使程序运行几次猜测是错误的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆