0 Fundamentals python-2.11 back to our game

Source: Internet
Author: User

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

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.