Guess number Game-python

Source: Internet
Author: User

Topic:

Write a guessing game in Python with the following rules:

1. Randomly write an integer 1-99 (for example: 21) by a single person

2. A group of small partners to guess the number, as the first person to guess a number (such as: 48), then narrow the range to (1-48)

3. If the second person guesses a number (for example: 9), the narrowing is (9-48)

4. And so on until the Guess number (21), the game is over

Analysis:

1. Randomly generate random numbers using the random module

2. If the input value is greater than NUM1 and less than the random number, the num1= input value

3. If the input value is less than num2 greater than the random number, the num2= input value

Exercises

#coding: Utf-8
Random
Print ("---guess number---")
num1=1
num2=99
Rd=random.randint (0,+)
Active=True
Active
Number=int ("Please write a random integer%d to%d (exit Please enter quit):"% (num1,num2))
    ifNUM1<NUMBER<RD:
Num1=number
elifNUM2>NUMBER>RD:
Num2=number
elifNUMBER==RD:
Print("Congratulations on your guess!")
Break
elifNum1>numberorNum2<number:#如果输入的number值小于1大于99则提示不符合要求
Print("The integer range you entered does not meet the requirements!")

elifnumber==quit:#如果input值为quit则退出
Active=False

Guess number Game-python

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.