Respuesta :
Answer:
import random
arr=[]
for i in range(100):
arr.append(i)
while True:
answer=random.choice(arr)
guess=int(input("enter your guess number between 0-100: "))
if answer is guess:
print("right guess\ncongratulations.....")
print("the answer was: "+str(answer))
break
elif guess < answer-20:
print("you guessed too low....\ntry again")
print("the answer was: "+str(answer))
elif guess > answer+20:
print("you guessed too high....\ntry again")
print("the answer was: "+str(answer))
else:
print("incorrect guess\ntry again")
print("the answer was: "+str(answer))
Explanation:
Following are the Python program to the given question:
Program Explanation:
- Import random package.
- Printing message, and defining "n" variable that uses the random method that select a random value between 1 to 100.
- In the next step, a while loop is defined that declare a "guess" variable that input value from the user-end.
- After input value, a conditioanl statement is declared that guesses the random variable value.
- And in the another block its checks the range value.
Program:
import random#import package
print("This is a number guessing game.")#print message
print("Guess what number we thought of between 1 and 100")#print message
n = random.randrange( 100 ) + 1#defining a variable n that uses random method that holds a value
while True:#defining a loop to input value and check value
guess = int(input('Enter your best guess!\n'))#defining a variable guess that inputs value
if guess == n:#defining if block that check the random number
print("Congrats, you won!")#print message
print("Restarting game") #print message
n = random.randrange( 100 ) + 1 #calling random method that holds a value
elif guess < n:#defining elif that check random number value less than inputs
print('too low,try again')#print message
else:#defining else block
print('too high try again.')#print message
Output:
Please find the attached file.
Learn more:
brainly.com/question/15018109
