-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumber_Guessing_Game.py
More file actions
62 lines (48 loc) · 2.03 KB
/
Number_Guessing_Game.py
File metadata and controls
62 lines (48 loc) · 2.03 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import random
art = """
________ ___________.__ _______ ___.
/ _____/ __ __ ____ ______ ______ \__ ___/| |__ ____ \ \ __ __ _____\_ |__ ___________
/ \ ___| | \_/ __ \ / ___// ___/ | | | | \_/ __ \ / | \| | \/ \| __ \_/ __ \_ __
\ \_\ \ | /\ ___/ \___ \ \___ \ | | | Y \ ___/ / | \ | / Y Y \ \_\ \ ___/| | \/
\______ /____/ \___ >____ >____ > |____| |___| /\___ > \____|__ /____/|__|_| /___ /\___ >__|
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/
"""
# Variables
msy_number = random.randint(1, 100)
HARD_LIVES = 5
EASY_LIVES = 10
user_lives = 0
game_over = False
def guess_checker(x):
global game_over
global user_lives
# Checks if the user guessed the number
if msy_number == x:
print("Congratulations you guessed the number!")
game_over = True
# Prints an output of higher or lower depending on the user's guesses
else:
if msy_number > x:
print("Too Low.")
user_lives = user_lives - 1
print(f"You have {user_lives} attempts remaining to guess the number")
else:
print("Too High.")
user_lives = user_lives - 1
print(f"You have {user_lives} attempts remaining to guess the number")
# Start of code
print(art)
print("Welcome to the Number Guessing Game!")
print("I'm thinking of a number between 1 - 100")
difficulty = input("Choose a difficulty. Type 'easy' or 'hard': ").lower()
if difficulty == "easy":
user_lives = EASY_LIVES
else:
user_lives = HARD_LIVES
while not game_over:
guess = int(input("Make a guess: "))
guess_checker(guess)
if user_lives == 0:
game_over = True
print(f"You have run out of guesses, the mystery number is {msy_number}")
print("Thanks for playing")