🔹 Introduction

The Number Guessing Game is a classic beginner Python project.
- The computer randomly picks a number.
- The player tries to guess it.
- The program gives hints if the guess is too high or too low.
- The game continues until the player guesses correctly.
🔹 Code Example
import random
print("🎮 Welcome to the Number Guessing Game!")
print("I am thinking of a number between 1 and 100.")
# Generate a random number
secret_number = random.randint(1, 100)
# Track attempts
attempts = 0
guessed = False
while not guessed:
try:
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 {secret_number} in {attempts} attempts.")
guessed = True
except ValueError:
print("⚠️ Please enter a valid number.")
🔹 Example Run
🎮 Welcome to the Number Guessing Game!
I am thinking of a number between 1 and 100.
👉 Enter your guess: 50
📉 Too low! Try again.
👉 Enter your guess: 75
📈 Too high! Try again.
👉 Enter your guess: 62
📉 Too low! Try again.
👉 Enter your guess: 68
🎉 Congratulations! You guessed the number 68 in 4 attempts.
🔹 Concepts Learned
- random.randint() → generates random numbers.
- while loop → repeat until condition is true.
- if/elif/else → decision-making.
- Exception handling → avoid crashes with invalid input.
🔹 Summary
- Created a Number Guessing Game using Python.
- Practiced random module, loops, conditionals, and error handling.
- This project can be extended (e.g., adding difficulty levels, limited attempts, or scoring system).