Skip to content

Commit 14f0b44

Browse files
authored
Merge pull request #19 from Blacksujit/black-sujit1
[❇️❇️game improvement ❇️❇️]added the new feature in the guessing game
2 parents 2e2ec5c + 3d17205 commit 14f0b44

File tree

1 file changed

+65
-6
lines changed

1 file changed

+65
-6
lines changed

Diff for: Game-Galore/guessing_game.py

+65-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,44 @@
11
import random
22

33
def guessing_game():
4-
print("Welcome to the Number Guessing Game!")
5-
lower_bound = 1
6-
upper_bound = 100
4+
# Welcome and difficulty level introduction
5+
print("Welcome to the Enhanced Number Guessing Game!")
6+
7+
# Adding difficulty levels (Easy, Medium, Hard)
8+
print("Choose a difficulty level: ")
9+
print("1. Easy (1-50, 15 attempts)")
10+
print("2. Medium (1-100, 10 attempts)")
11+
print("3. Hard (1-200, 7 attempts)")
12+
13+
# Input to select difficulty level
14+
while True:
15+
try:
16+
difficulty = int(input("Enter 1, 2, or 3 for difficulty: "))
17+
if difficulty == 1:
18+
lower_bound = 1
19+
upper_bound = 50
20+
max_attempts = 15
21+
break
22+
elif difficulty == 2:
23+
lower_bound = 1
24+
upper_bound = 100
25+
max_attempts = 10
26+
break
27+
elif difficulty == 3:
28+
lower_bound = 1
29+
upper_bound = 200
30+
max_attempts = 7
31+
break
32+
else:
33+
print("Invalid choice. Please select a valid difficulty (1, 2, or 3).")
34+
except ValueError:
35+
print("Invalid input. Please enter a number (1, 2, or 3).")
36+
737
secret_number = random.randint(lower_bound, upper_bound)
838
attempts = 0
9-
max_attempts = 10
39+
score = 100 # Initial score for tracking how well the user performs
1040

11-
print(f"I've selected a number between {lower_bound} and {upper_bound}. You have {max_attempts} attempts to guess it.")
41+
print(f"\nI've selected a number between {lower_bound} and {upper_bound}. You have {max_attempts} attempts to guess it.")
1242

1343
while attempts < max_attempts:
1444
try:
@@ -24,13 +54,42 @@ def guessing_game():
2454
elif guess > secret_number:
2555
print("Too high!")
2656
else:
27-
print(f"Congratulations! You've guessed the number {secret_number} in {attempts} attempts.")
57+
print(f"🎉 Congratulations! You've guessed the number {secret_number} in {attempts} attempts!")
58+
print(f"Your final score is {score - (attempts * 5)} points!") # Subtract points based on attempts
2859
break
60+
61+
# Adding hints after incorrect guesses
62+
if guess != secret_number:
63+
if secret_number % 2 == 0:
64+
print("Hint: The secret number is even.")
65+
else:
66+
print("Hint: The secret number is odd.")
67+
68+
difference = abs(secret_number - guess)
69+
if difference > 50:
70+
print("Hint: You're way off! More than 50 away!")
71+
elif difference > 20:
72+
print("Hint: Getting warmer! You're 20-50 away.")
73+
elif difference > 10:
74+
print("Hint: You're within 10-20 of the number!")
75+
else:
76+
print("Hint: Very close! You're within 10 of the number!")
77+
2978
except ValueError:
3079
print("Invalid input. Please enter an integer.")
3180

81+
# If user has used all attempts
3282
if attempts == max_attempts:
3383
print(f"Sorry, you've used all your attempts. The secret number was {secret_number}.")
84+
print(f"Your final score is {score - (attempts * 5)} points.")
85+
86+
# Adding replay option to make the game more dynamic
87+
replay = input("Would you like to play again? (yes/no): ").strip().lower()
88+
if replay == 'yes':
89+
guessing_game() # Recursively call the game function for a new round
90+
else:
91+
print("Thanks for playing! Goodbye!")
92+
3493

3594
if __name__ == "__main__":
3695
guessing_game()

0 commit comments

Comments
 (0)