Python cycle guessing age game

Source: Internet
Author: User

One, using the while loop guessing age game:

1 #Author:yebo2Count =03Age_of_yebo = 204  whileCount < 3:5 6guess_age = Int (input ("Guess Age:"))#Input the number entered by default is in string form, to be converted to int type7 8     ifAge_of_yebo = =Guess_age:9         Print("congratulations!")Ten          Break One     elifAge_of_yebo >Guess_age: A         Print("Guess bigger!") -     Else: -         Print("Guess smaller!") theCount +=1 - Else: -     Print("You tried too many times.")

Second, use for loop guessing age game:

1 #Author:yebo2 3Age_of_yebo = 204 5  forIinchRange (3):6guess_age = Int (input ("Guess Age:"))#Input the number entered by default is in string form, to be converted to int type7 8     ifAge_of_yebo = =Guess_age:9         Print("congratulations!")Ten          Break One     elifAge_of_yebo >Guess_age: A         Print("Guess bigger!") -     Else: -         Print("Guess smaller!") the Else: -     Print("You tried too many times.")

Third, upgrade version guess age game:

1 #Author:yebo2Count =03Age_of_yebo = 204  whileCount < 3:5 6guess_age = Int (input ("Guess Age:"))7 8     ifAge_of_yebo = =Guess_age:9         Print("congratulations!")Ten          Break One     elifAge_of_yebo >Guess_age: A         Print("Guess bigger!") -     Else: -         Print("Guess smaller!") theCount +=1 -     ifCount = = 3: -Continue_confirm = input ("want to keep trying?") -         ifContinue_confirm! ="N": +Count = 0

Python cycle guessing age 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.