import random

def guess_number():
    # Generate a random number between 1 and 100
    secret_number = random.randint(1, 100)
    attempts = 5  # Number of attempts allowed
    print("Welcome to the Number Guessing Game!") #GREETINGS USERS
    print("I have selected a number between 1 and 100. You have", attempts, "attempts to guess it.")

    # Loop until the user runs out of attempts or guesses correctly
    while attempts > 0:
        guess = int(input("Enter your guess: "))  # take input from the user
        attempts -= 1

        # Check if the guess is correct
        if guess == secret_number:
            print("Congratulations! You guessed the number correctly.")
            break
        elif guess < secret_number:
            print("Too low! Try again.")
        else:
            print("Too high! Try again.")

        # Inform the user of remaining attempts
        if attempts > 0:
            print("You have", attempts, "attempts left.")
        else:
            print("You have run out of attempts. The number was", secret_number)

    play_again = input("Do you want to play again? (yes/no): ") # check if user wants guessing again
    if play_again.lower() == "yes":
        guess_number()
    else:
        print("Thank you for playing!")

# Start the game
guess_number()
