-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday13_game_same_as_day12.py
More file actions
47 lines (39 loc) · 1.26 KB
/
day13_game_same_as_day12.py
File metadata and controls
47 lines (39 loc) · 1.26 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
import random
import art
print(art.logo)
EASY_LEVEL_TURNS = 50
HARD_LEVEL_TURNS = 5
def set_difficulty():
level = input("Choose a difficulty level. Type 'easy' or 'hard': ").lower()
if level == 'easy':
return EASY_LEVEL_TURNS
elif level == 'hard':
return HARD_LEVEL_TURNS
else:
print("Invalid input. Defaulting to 'hard'.")
return HARD_LEVEL_TURNS
def check_answer(your_guess, rand_number):
if your_guess < rand_number:
print("Too low. Guess again.")
return False
elif your_guess > rand_number:
print("Too high. Guess again.")
return False
else:
print(f"🎉 Correct! The number was {rand_number}.")
return True
def game():
rand_number = random.randint(1, 100)
print("Welcome to the Number Guessing Game!")
print("I'm thinking of a number between 1 and 100.")
attempt = set_difficulty()
while attempt > 0:
your_guess = int(input("Make a guess: "))
is_correct = check_answer(your_guess, rand_number)
if is_correct:
break
attempt -= 1
print(f"You have {attempt} attempts remaining.")
if attempt == 0:
print(f"You've run out of guesses. The number was {rand_number}. You lose.")
game()