Python Guess small game

Source: Internet
Author: User

  • Randomly generate a number between 1 and 100 using the random variable

  • Collect the number entered by the user, if the input does not meet the requirements will let the user re-enter.

  • Enter meet requirements and the game starts. If the number is greater than the random number, the output number is too large; if it is less than the random number, the output number is too small

  • Guess right, the output number is correct, guess the number of times, and ask whether to continue the game

  • User answer Y (yes) means to continue playing

  • Import randomrnum=random.randint (1,100) count=0while true:    num=input (' please  enter a number (1,100):  \n '). Strip ()     if num.isdigit ():         num=int (num)         count  += 1        if num == rnum:             print (' yes,{} is right;you guess  {} times '. Format (num,count)              ask=input (' Would you like play again (y/n):  \n '). Strip (). Lower ()              if ask ==  ' y ':                 continue             else:                 break            break         elif num > rnum:             print (' you number is too lager! ')             continue         else:            print (' You  number is too small! ')             continue    else:         print (' You number is invalid,please enter  again ')         continue


    Python Guess small game

    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.