Classes/Spring 2025/ENGR 490/4/A4/Scripts/guess_number.py

24 lines
531 B
Python

# Import time and random modules
import random
import time
# Set the Seed based off time
random.seed(time.time())
# Generate Random number 1 - 10
ans = random.randint(1,10)
while(1):
guess = int(input("Enter your guess: "))
if (guess == ans):
print(f"Correct! The answer is {ans}!")
break
elif (guess > ans):
print(f"{guess} is too high! Try Again!")
elif (guess < ans):
print(f"{guess} is too low! Try Again!")
else:
print(f"{guess} is invalid answer! Try Again!")