from random import randint

def play_game():
    n = randint(1, 50)
    print("I'm thinking of a number between 1 and 50.")
    print("You have 5 attempts to guess the number.")

    attempts = 5

    while attempts > 0:
        guess = int(input("Guess a number: "))
        attempts -= 1

        if guess < n:
            print("Higher!")
        elif guess > n:
            print("Lower!")
        else:
            print("Good job, you did it!")
            break

        print(f"You have {attempts} more attempts.")

    else:
        print("Unfortunately, your attempts have ended.")
        print(f"The number was {n}.")

if __name__  == "__main__":
    play_game()
    
    restart = input("Do you want to play again? (yes/no): ")

    while restart.lower() == "yes":
        play_game()
        restart = input("Do you want to play again? (yes/no): ")