The last time our game added conditional judgment, but it can only be guessed to the user once, very difficult to guess
So, we have this class in the game to add a loop, let the user guess a few more times
First, the original code:
Print ("---------Welcome to the place to guess the numbers, start---------") #输出提示guess =int (Input ("* Number range 0-100, enter the number you guessed:")) #读取输入, and then assign print (guess) # Printing input secret=18if Guess==secret: Print ("Congratulations, guess right") Else: print (" Sorry, Wrong guess") print ("Game Over")
In addition, we introduce random numbers in this program, so we can guess the numbers differently every time.
So that's when we started the program.
Import Randomsecret=random.randint (1,100) #生成随机数 #print (secret) time=6# guess number of times guess=0# input number minnum=0# minimum random number maxnum=100 #最大随机数print ("---------Welcome to the place where you guessed the numbers, start---------") while Guess!=secret and time>=0: #条件 guess=int ("* Number Interval 0-100, enter the number you guessed: ")" print ("You enter the number is:", guess) if Guess==secret: print ("guessed right, really bad") else: # When not equal, you also need to print out the corresponding interval, making it easier for users to use if Guess<secret: minnum=guess print ("Your guess is less than the correct answer") print (" The current number range is: ", Minnum,"-", Maxnum) else: maxnum=guess print (" Your guess is greater than the correct answer ") print (" Number range is: ", minnum , "-", Maxnum) print ("Too bad, you guessed wrong, you have", Time, "chance") Time-=1print ("Game Over")
This time the game is quite perfect, but it can only provide a user to play, we will introduce the next lesson to the list
So as to realize the function of multi-user guessing.
This is the section here, thank you.
------------------------------------------------------------------
Click to jump 0 basic python-Catalogue
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
0 Fundamentals python-2.13 back to our game join the loop