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