-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay 12 python.py
More file actions
30 lines (26 loc) · 899 Bytes
/
Day 12 python.py
File metadata and controls
30 lines (26 loc) · 899 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
# number guessing game
import random
def guess_number_game(attempts, number):
while attempts > 0:
print(f"You have {attempts} attempts remaining to guess the number.")
guess = int(input("Make a guess: "))
if guess == number:
print(f"You got it! The answer was {number}.")
return
elif guess > number:
print("Too high.")
else:
print("Too low.")
attempts -= 1
print(f"You've run out of attempts! The number was {number}.")
difficulty = input("Choose a difficulty (easy/hard): ")
if difficulty == "easy":
attempts = 10
number = random.randint(1, 100)
guess_number_game(attempts, number)
elif difficulty == "hard":
attempts = 5
number = random.randint(1, 100)
guess_number_game(attempts, number)
else:
print("Invalid difficulty choice.")