- import random
- def guessing_game():
- print("Welcome to the Guessing Game!")
- print("I'm thinking of a number between 1 and 100.")
- print("Try to guess the number.")
- secret_number = random.randint(1, 100)
- attempts = 0
- while True:
- guess = int(input("Enter your guess: "))
- attempts += 1
- if guess < secret_number:
- print("Too low! Try again.")
- elif guess > secret_number:
- print("Too high! Try again.")
- else:
- print(f"Congratulations! You guessed the number in {attempts} attempts.")
- break
- guessing_game()
[text] guessing game
Viewer
Editor
You can edit this paste and save as new:
File Description
- guessing game
- Paste Code
- 09 Jun-2023
- 637 Bytes
You can Share it: