2016.8.21 quiz game, 2016.8.21 quiz

Source: Internet
Author: User

2016.8.21 quiz game, 2016.8.21 quiz

1 import random 2 secret = random. randint (1, 99) 3 guess = 0 4 tries = 0 5 print secret 6 print "Alex, I have a secret, It is a number from 1 to 99, you have 6 tries. "7 while guess! = Secret and tries <6: 8 guess = input ("Enter you guess number:") 9 if guess <secret: 10 print "too low" 11 elif guess> secret: 12 print "too hight" 13 tries ++ = 114 if guess = secret: 15 print "congratulations" 16 else: 17 print "no more tries"

1. About tries + = 1, in python, the statement block will not introduce new scopes separately. tries is still a global variable. Changing tries in while will change the value of the tries variable.

2. logical judgment. (1) guess! = Secret and tries <6. (2) guess = secret, (3) tries> = 6. When (1) is not met, there are two situations: (2) (3.

 

Related Article

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.