You are on page 1of 6

pythonCopy code

import random def guessing_game(): print("Welcome to the Guessing Game!") print("I have selected a random number betwee
andom number between 1 and 100.") # Generate a random number between 1 and 100 secret_number = random.randint(1, 100) attempts =
random.randint(1, 100) attempts = 0 while True: # Ask the player to guess the number guess = int(input("Your guess: ")) attempts += 1 # Ch
Your guess: ")) attempts += 1 # Check if the guess is correct if guess == secret_number: print(f"Congratulations! You guessed the correct nu
ations! You guessed the correct number {secret_number} in {attempts} attempts.") break elif guess < secret_number: print("Too low! Try aga
et_number: print("Too low! Try again.") else: print("Too high! Try again.") # Run the game guessing_game()

You might also like