The first program actually just prints something to the top of the screen, and below we introduce a game that makes the course more interesting.
The second program is a small game-guess numbers, I first put the code on
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")
It is possible now that we do not understand, we can first save the code as a Python file, and then run it, look at the effect, the next section, we will discuss some of the python some of the introductory questions.
I'll explain to you the above code:
1. Random Numbers by program
2. User input number guessing
3. The program determines the size according to the input, then gives the corresponding prompt
4. The user keeps trying until the number of guesses or guesses is greater than the number of times the preset value
5. If guessed, the player wins, wrong guess, again
This is the section here, thank you.
------------------------------------------------------------------
Click to jump 0 basic python-Catalogue
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 Basic python-1.7 Second program