The implementation allows users to constantly guess age, but only give up to 3 opportunities, more than the number of guesses to quit the program.

Source: Internet
Author: User

#!/usr/bin/env python
#-*-Coding:utf-8-*-
# __author__ = "Sandu"

My_age =27
Count =0

While Count <3:
Guess_age =intInput "Please enter your guess Age:"))
Count + = 1
if guess _age > My_age:
print ( "Age guess Big")
if count = = 3:
print (" has exceeded the number of inputs ")
elif guess_age < my_age:
print (" Age Guess small ")
if count = = 3:
print (" has exceeded the number of inputs ")
else:
print (" Congratulations, you guessed it! ")
< Span style= "COLOR: #008080" > < Span style= "COLOR: #0000ff" > < Span style= "COLOR: #0000ff" > break

########### #改良版本 #####################
#!/usr/bin/env python
#-*-Coding:utf-8-*-
# __author__ = "Sandu"

My_age =27
Count =0
while count < 3:
Guess_age = int (input (" Please enter your guess Age: "))
if guess_age > My_age:
print (" Age guess Big ")
elif guess_age < my_age:
print (" Age guess small)
else:
print ( "Congratulations, you guessed it!" ")
break
count + = 1
else:
print (
< Span style= "COLOR: #008080" > < Span style= "COLOR: #0000ff" > < Span style= "COLOR: #0000ff" > < Span style= "COLOR: #000080" > 


The

Implementation allows the user to constantly guess age, but only to a maximum of 3 opportunities, more than the number of guesses to quit the 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.