-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathguess_the_number.py
More file actions
34 lines (29 loc) · 915 Bytes
/
guess_the_number.py
File metadata and controls
34 lines (29 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
"""
🎯 Guess the Number Game
A simple Python command-line game for fun.
Author: YourName
License: MIT
"""
import random
def play_game():
print("🎮 Welcome to the Guess the Number Game!")
print("I'm thinking of a number between 1 and 100...")
number = random.randint(1, 100)
attempts = 0
while True:
try:
guess = int(input("👉 Enter your guess: "))
attempts += 1
if guess < number:
print("📉 Too low! Try again.")
elif guess > number:
print("📈 Too high! Try again.")
else:
print(f"🎉 Correct! The number was {number}.")
print(f"You guessed it in {attempts} attempts! 🏆")
break
except ValueError:
print("⚠️ Please enter a valid number.")
if __name__ == "__main__":
play_game()