-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumber_guessing_game.py
64 lines (45 loc) · 1.5 KB
/
number_guessing_game.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
53
54
55
56
57
58
59
60
61
62
63
64
logo = """
________ ___ ___ _______ ________ ________
|\ ____\|\ \|\ \|\ ___ \ |\ ____\ |\ ____\
\ \ \___|\ \ \\\ \ \ __/|\ \ \___|_\ \ \___|_
\ \ \ __\ \ \\\ \ \ \_|/_\ \_____ \\ \_____ \
\ \ \|\ \ \ \\\ \ \ \_|\ \|____|\ \\|____|\ \
\ \_______\ \_______\ \_______\____\_\ \ ____\_\ \
\|_______|\|_______|\|_______|\_________\\_________\
\|_________\|_________|
"""
from random import randint
easy_level = 10
hard_level = 5
def check_answer(guess, AI, turns):
if guess > AI:
print("Too high")
return turns - 1
elif guess < AI:
print("Too low")
return turns - 1
else:
print(f"You got it right! The answer was {AI}")
def set_difficulty():
level = input("Choose a difficulty. Type 'easy' or 'hard': ")
if level == "easy":
return easy_level
elif level == "hard":
return hard_level
def game():
print(logo)
print("Welcome to the number guessing game!")
print("I'm thinking of a number between 1 and 100")
AI = randint(1, 100)
turns = set_difficulty()
guess = 0
while guess != AI:
print(f"You have {turns} attempts remaining to guess the number")
guess = int(input("Make a guess: "))
turns = check_answer(guess, AI, turns)
if turns == 0:
print("You 've run out of guesses, you lose.")
return
elif turns != 0:
print("Guess again")
game()