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

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.