Answer:
In Python:
import random
computerguess = random.randint(1,101)
userguess = int(input("Take a guess: "))
while not (userguess == computerguess):
if userguess<1 or userguess>100:
print("Error")
elif not (userguess == computerguess):
if userguess < computerguess:
print("Too small")
else:
print("Too large")
userguess = int(input("Take a guess: "))
print("Congratulations")
Step-by-step explanation:
This imports the random module
import random
Here, a random number is generated
computerguess = random.randint(1,101)
This prompts the user for a guess
userguess = int(input("Take a guess: "))
The following loop is repeated until the user guess correctly
while not (userguess == computerguess):
If user guess is not between 1 and 100 (inclusive)
if userguess<1 or userguess>100:
This prints error
print("Error")
If the user guessed is not correct
elif not (userguess == computerguess):
If the user guess is less
if userguess < computerguess:
It prints too small
print("Too small")
If otherwise
else:
It prints too large
print("Too large")
This prompts the user for a guess
userguess = int(input("Take a guess: "))
The loop ends here
This prints congratulations when the user guess correctly
print("Congratulations")