import random def guess_the_number(): print("Welcome to the Number Guessing Game!") print("I am thinking of a number between 1 and 100.") # Generate a random number between 1 and 100 number_to_guess = random.randint(1, 100) attempts = 0 guessed_correctly = False # Start the guessing loop while not guessed_correctly: try: # Get user input user_guess = int(input("Enter your guess: ")) attempts += 1 # Check if the guess is too high, too low, or correct if user_guess < number_to_guess: print("Too low! Try again.") elif user_guess > number_to_guess: print("Too high! Try again.") else: guessed_correctly = True print(f"Congratulations! You've guessed the correct number {number_to_guess} in {attempts} attempts.") except ValueError: print("Please enter a valid number.") # Run the game guess_the_number()