8000 enhancements · d-coder111/SpectrumOfPython@dbafaf7 · GitHub
[go: up one dir, main page]

Skip to content

Commit dbafaf7

Browse files
committed
enhancements
1 parent 983cb3d commit dbafaf7

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed
File renamed without changes.

Game-Galore/guessing_game.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import random
2+
3+
def guessing_game():
4+
print("Welcome to the Number Guessing Game!")
5+
lower_bound = 1
6+
upper_bound = 100
7+
secret_number = random.randint(lower_bound, upper_bound)
8+
attempts = 0
9+
max_attempts = 10
10+
11+
print(f"I've selected a number between {lower_bound} and {upper_bound}. You have {max_attempts} attempts to guess it.")
12+
13+
while attempts < max_attempts:
14+
try:
15+
guess = int(input("Enter your guess: "))
16+
attempts += 1
17+
18+
if guess < lower_bound or guess > upper_bound:
19+
print(f"Please guess a number between {lower_bound} and {upper_bound}.")
20+
continue
21+
22+
if guess < secret_number:
23+
print("Too low!")
24+
elif guess > secret_number:
25+
print("Too high!")
26+
else:
27+
print(f"Congratulations! You've guessed the number {secret_number} in {attempts} attempts.")
28+
break
29+
except ValueError:
30+
print("Invalid input. Please enter an integer.")
31+
32+
if attempts == max_attempts:
33+
print(f"Sorry, you've used all your attempts. The secret number was {secret_number}.")
34+
35+
if __name__ == "__main__":
36+
guessing_game()
File renamed without changes.

0 commit comments

Comments
 (0)
0