π― Guess Master is a fun and interactive Python number-guessing game where the computer secretly chooses a number between 1 and 100. Try to find the hidden number using hints like βToo High!β or βToo Low!β. Your attempts are counted, and you can quit anytime. Can you find the number in the fewest guesses? ππ₯
here's the code:
import random
def start_game():
secret_number = random.randint(1, 100)
attempts = 0
print("Welcome to the Number Guessing Game!")
print("I am thinking of a number between 1 and 100.")
while True:
user_input = input("Take a guess (or type 'quit' to exit): ").strip()
if user_input.lower() == 'quit':
print(f"Thanks for playing! The number was {secret_number}.")
break
if not user_input.isdigit():
print("Please enter a valid whole number.")
continue
guess = int(user_input)
attempts += 1
if guess < secret_number:
print("Too low! Try again.")
elif guess > secret_number:
print("Too high! Try again.")
else:
print(f"π Correct! You found the number in {attempts} attempts!")
break
Run the game
if name == "main":
start_game()
Top comments (1)
a good number guesser game try it out