154k views
3 votes
Implement the GuessNumber game. In this game, the computer Think of a random number in the range 0-50. (Hint: use the random module.) Repeatedly prompt the user to guess the mystery number. If the guess is correct, congratulate the user for winning. If the guess is incorrect, let the user know if the guess is too high or too low. After 5 incorrect guesses, tell the user the right answer.

1 Answer

2 votes

Answer:

import random

arr=[]

for i in range(50):

arr.append(i)

for j in range(5):

answer=random.choice(arr)

guess=int(input("enter your guess number between 0-50: "))

if answer is guess:

print("right guess\\congratulations.....")

print("the answer was: "+str(answer))

break

elif guess < answer-10:

print("you guessed too low....\\try again")

print("the answer was: "+str(answer))

elif guess > answer+10:

print("you guessed too high....\\try again")

print("the answer was: "+str(answer))

else:

print("incorrect guess\\try again")

print("the answer was: "+str(answer))

Step-by-step explanation:

the code is in python language

User Homr Zodyssey
by
6.9k points