Guessing game
Guessing game
1937 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
>>>
>>> def guessing_game():
... print("Welcome to the Guessing Game!")
... number_to_guess = random.randint(1, 100)
... number_of_attempts = 0
... player_guess = None
...
... while player_guess != number_to_guess:
... player_guess = int(input("Guess a number between 1 and 100: "))
... number_of_attempts += 1
...
... if player_guess < number_to_guess:
... print("Too low! Try again.")
... elif player_guess > number_to_guess:
... print("Too high! Try again.")
...
... print(f"Congratulations! You guessed the correct number {number_to_guess}
in {number_of_attempts} attempts.")
...
>>> # Run the game
>>> guessing_game()
Welcome to the Guessing Game!
Guess a number between 1 and 100: 11
Too low! Try again.
Guess a number between 1 and 100: 33
Too low! Try again.
Guess a number between 1 and 100: 65
Too high! Try again.
Guess a number between 1 and 100: 50
Too low! Try again.
Guess a number between 1 and 100: 60
Too high! Try again.
Guess a number between 1 and 100: 59
Too high! Try again.
Guess a number between 1 and 100: 55
Too high! Try again.
Guess a number between 1 and 100: 54
Congratulations! You guessed the correct number 54 in 8 attempts.
>>>