@kr9c

import random

# Function to play the game
def play_game():
    print("Welcome to Guess the Number!")
    
    # Generate a random number between 1 and 100
    secret_number = random.randint(1, 100)
    
    attempts = 0
    guessed = False
    
    while not guessed:
        # Prompt the player for a guess
        guess = int(input("Enter your guess (1-100): "))
        
        # Increment the number of attempts
        attempts += 1
        
        # Compare the guess with the secret number
        if guess == secret_number:
            print("Congratulations! You guessed the number in", attempts, "attempts.")
            guessed = True
        elif guess < secret_number:
            print("Too low! Try again.")
        else:
            print("Too high! Try again.")

# Start the game
play_game()