-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
52 lines (36 loc) · 1.18 KB
/
main.py
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
from random import randint
from art import logo
EASY_LEVEL_TURNS = 10
HARD_LEVEL_TURNS = 5
def check_answer(guess, answer, turns):
if guess > answer:
print("Too high. ")
return turns - 1
elif guess < answer:
print("Too low. ")
return turns - 1
else:
print(f"You got it! The answer was {answer}. ")
def set_difficulty():
level = input("Choose a difficulty. Type 'easy' or 'hard': ")
if level == "easy":
return EASY_LEVEL_TURNS
else:
return HARD_LEVEL_TURNS
def game():
print(logo)
print("Welcome to the Number Guessing Game!")
print("I'm thinking of a number between 1 and 100. ")
answer = randint(1, 100)
turns = set_difficulty()
guess = 0
while guess != answer:
print(f"You have {turns} attempts remaining to guess the number. ")
guess = int(input("Make a guess: "))
turns = check_answer(guess, answer, turns)
if turns == 0:
print("You've run out of guesses, you lose.")
return
elif guess != answer:
print("Guess again. ")
game()