Define Guess numbers game function

Source: Internet
Author: User

#Guess number GameImportRandomdefNumgame (self): Total=0 while1:        #because IsDigit is judged below, NUM is treated as a str type, and num on the back requires a separate int, which does not take effect if the line int (num) is on totalnum = input ("Please enter the number in 0-999, enter-1 end:")        ifnum = ="-1":             Break        elifNum.isdigit () and0 <= Int (num) < 1000: Num=int (num) total+ = 1Print("you have effectively entered%d times"%Total ) Random_num= Random.randrange (0,1000)            ifnum >Random_num:Print("the number you entered is larger than the program random number, and the program random number is%d."%random_num)elifnum = =Random_num:Print("you guessed it, the program random number is%d."%random_num)Else:                Print("the number you entered is smaller than the program random number, and the program random number is%d."%random_num)Else:            Print("input wrong, please re-enter! ")if __name__=="__main__": Numgame (0)

Define Guess numbers game function

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.