0 Basic python-1.7 Second program

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.