Python on the first day a few small games

Source: Internet
Author: User

1. Guess the age, you can let the user guess up to three times!

1Print"---------welcome to guessing age game---------") # Print game title2 3Guess =3#准许猜测次数4 5Age = about# Age equals6 7  whileGuess >0: #循环执行8 9User_guess =int(input ("Enter the age you guessed:") # Enter a guess valueTen  one print (type (USER_GUESS)) # printing input type a  -     ifUser_guess >age : # If it's larger than print below -  thePrint"try the smaller ...") -  -     elifUser_guess <age : # if, if less than, print below -  +Print"try the bigger ...") -  +     Else: # Otherwise print below a  atPrint"you guessed it!") -  -guess-=1#执行一次, the number of guesses is reduced once

2. Guess the age, every 3 times, ask him, also want to continue to play, y (continue), n (stop)

1Print"---------welcome to guessing the age and playing games---------") # Print game title2 3Age = about# Age equals4 5Guess =1#猜测次数默认值6 7 8  whileTrue: #循环为真执行9     ifGuess >3: #如果猜测大于3Tenpursue_carry_on = input ("do you want to keep guessing? y or n") one         ifpursue_carry_on = ="y": #必须输入小写y aGuess =1 -         Else: -  break thePrint"the game is about to start you have a total of 3 opportunities, this is the first", guess,"Second Chance"# Indicates the number of console sessions -  -User_guess =int(input ("Enter the age you guessed:"))  # -  +  -     ifUser_guess >age : # If it's larger than print below +  aPrint"try the smaller ...") at  -     elifUser_guess <age : # if, if less than, print below -  -Print"try the bigger ...") -  -     Else: # Otherwise print below in  -Print"you guessed it!") to  break +  -Guess + =1#执行一次, the number of guesses added once

3, Write the login interface input user name password Authentication successful display welcome information three times after the wrong lock

Python on the first day a few small games

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.