Untitled
Anonymous
plain_text
02/09/2026 10:42 PM
1.5 KB
13
Indexable
import random
def guessing_game():
print("๐ฎ Welcome to the Number Guessing Game!")
print("I'm thinking of a number between 1 and 100.")
print("Try to guess it!\n")
secret_number = random.randint(1, 100)
attempts = 0
while True:
guess = input("Enter your guess (or type 'quit' to exit): ")
if guess.lower() == "quit":
print(f"๐ You quit! The number was {secret_number}.")
break
if not guess.isdigit():
print("โ Please enter a valid number.")
continue
guess = int(guess)
attempts += 1
if guess < secret_number:
print("๐ Too low! Try again.\n")
elif guess > secret_number:
print("๐ Too high! Try again.\n")
else:
print(f"๐ Correct! You guessed the number in {attempts} attempts.")
break
if __name__ == "__main__":
guessing_game()
โถ๏ธ How to Run It
Install Python (if you donโt have it)
Save the file as guessing_game.py
Open a terminal or command prompt
Run:
python guessing_game.pyEditor is loading...
Leave a Comment