One of python games -------- guess numbers

Source: Internet
Author: User

I took a look at the python getting started book and used a small game to train my hands. In fact, there are just a few lines of code, and only the novice and the cheek-to-face loggings make me look ugly.

Just like Zhang xzhong, come to Shanghai, and the tianchao naval forces are invincible.

Here is the use of a random function and A while LOOP statement.


#-*-Encoding: UTF-8-*-''' Created on August 1, May 8, 2014 @ author: Administrator ''' import randomkeys = random. randint (1,100) # The function is used to give a random number, then let's guess the number of times = 0 # The number of guesses your_key = 0 # define a variable print that waits for the value entered by the user. "You are playing a number-guessing game, you have 6 chances to guess @ "while your_key! = Keys and times <6: your_key = int (raw_input ("enter a number that you think is correct:>") if your_key> keys: print "the number you entered is too large. Please enter a smaller value :) \ n" elif your_key

 

  

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.