0 Fundamentals python-2.13 back to our game join the loop

Source: Internet
Author: User

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

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.