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.py
Editor is loading...
Leave a Comment