Back to our game today, we add conditional judgment statements to our game and enrich gameplay
Our previous 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) # Print input
The above is our previous code, relatively simple, just print the number you entered, forget it.
We're in there today to add conditional judgments that make the game rich dot
1. First we set the good one constant in the original code, as we need to guess the number
such as: secret=18;
2. Add conditional judgment to determine if the input guess is equal to secret, if you think output congratulations, otherwise output sorry
Such as:
If Guess==secret:
Print ("Congratulations, guess right")
Else
Print ("Sorry, wrong guess")
So, our improved code is the following:
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")
The following results can be obtained by running:
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.11 back to our game