Repository navigation
Expand file tree
/
Copy pathNum_Guess.py
More file actions
65 lines (55 loc) · 2.01 KB
/
Copy pathNum_Guess.py
File metadata and controls
65 lines (55 loc) · 2.01 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import random
from Score import ScoreManager
p = 1
score = ScoreManager()
print("🎯 Welcome to the Number Guessing Game!")
print("I am thinking of a number between 1 and 100... Can you guess it?")
def play_game():
print("\nChoose your difficulty: Easy (10 attempts) or Hard (5 attempts)")
# Difficulty setting
d = input("Enter difficulty (Easy/Hard) : ").strip().lower()
a = 10 if d == "easy" else 5
while True:
if d not in ["easy", "hard"]:
print("⚠️ Invalid difficulty. Please choose 'Easy' or 'Hard'.")
d = input("Enter difficulty (Easy/Hard) : ").strip().lower()
a = 10 if d == "easy" else 5
else:
break
# Generate the number
sn = random.randint(1, 100)
# Game loop
while a > 0:
print(f"\nYou have {a} attempts remaining.")
try:
g = int(input("Make a guess : "))
except ValueError:
print("⚠️ Please enter a valid number.")
continue
if g == sn:
print(f"🎉 Congrats! You guessed it right. The number was {sn}.")
points = p * 10 # Reward: more attempts left = more points
score.add_points(points)
print(f"You earned {points} points!")
break
elif g < sn:
print("🔼 Too low!")
else:
print("🔽 Too high!")
a -= 1
# If user fails
if a == 0 and g != sn:
print(f"\n💀 You've run out of guesses. The number was {sn}. Better luck next time!")
print("🕹️ Game Over")
# 🎮 Main Loop
while True:
play_game()
again = input("\nDo you want to play again? (yes/no): ").strip().lower()
if again != 'yes':
print("\n🎯 Final Score:", score.get_score())
if score.update_high_score():
print("🎉 New High Score:", score.get_high_score())
else:
print("🏆 High Score remains:", score.get_high_score())
print("👋 Thanks for playing! See you next time.")
break