Untitled
unknown
plain_text
6 months ago
763 B
2
Indexable
import random def guessing_game(): print("Welcome to the Number Guessing Game!") print("I'm thinking of a number between 1 and 100.") secret_number = random.randint(1, 100) attempts = 0 while True: guess = input("Enter your guess: ") # Check if the input is a number if not guess.isdigit(): print("Please enter a valid number.") continue guess = int(guess) attempts += 1 if guess < secret_number: print("Too low! Try again.") elif guess > secret_number: print("Too high! Try again.") else: print(f"Congratulations! You guessed the number in {attempts} attempts.") break # Run the game guessing_game()
Editor is loading...
Leave a Comment