Codes: import random def guess_the_number(): print(" Welcome to the Guess the Number Game!") print("I'm thinking of a number between 1 and 100. Can you guess what it is?") number_to_guess = random.randint(1, 100) attempts = 0 while True: try: user_guess = int(input("Your guess: ")) attempts += 1 if user_guess < number_to_guess: print("Too low ") elif user_guess > number_to_guess: print("Too high ") else: print(f"Congratulations! You guessed it right. The number was {number_to_guess}.") print(f"Total attempts: {attempts}") break except ValueError: print("Please enter a valid number.") guess_the_number()