Hey devs! π
Hereβs a fun and beginner-friendly project: a Number Guessing Game using Python! π―
π‘ What It Does
- Randomly picks a number between 1 and 100
- 7,5,3 attempts(based on your level) to guess the correct number
- Friendly feedback: π Too low / π Too high
- Tells you if your guess is too high or too low
- Includes input validation and emojis for fun!
π§ The Code
import random
number_to_guess = random.randint(1, 10)
attempts = 5
print("Welcome to the Number Guessing Game!π―")
print("I'm thinking of a number between 1 and 10.")
level = input("Choose difficulty (easy, medium, hard): ").lower()
if level == "easy":
attempts = 7
elif level == "medium":
attempts = 5
elif level == "hard":
attempts = 3
print(f"You have {attempts} attempts to guess the number.\nGood luck!π")
for attempt in range(attempts):
try:
guess = int(input("Enter your guess: "))
except ValueError:
print("Invalid input! Please enter a number.β")
continue
if guess == number_to_guess:
print("Congratulations! You guessed the number correctly.β
")
break
elif guess < number_to_guess:
print("Your guess is too low. Try again.π")
elif guess > number_to_guess:
print("Your guess is too high. Try again.π")
else:
print(f"Game over! The correct number was {number_to_guess}β")
π¦ GitHub Repository
π Check out the full code on GitHub
π Future Ideas
- Add difficulty levels
- Add a βPlay Againβ option
- Track guess history
Hope this helps fellow learners! π»β¨
Feel free to fork and improve!
Leave a comment if you built something similar π
Top comments (0)