-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththe_num_guess_game.py
57 lines (47 loc) · 2.27 KB
/
the_num_guess_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
import random
def play_game():
print('''
_ _ _ ____ _________ ______ _________ ____ _ _ _____ _________ _ _____
/ \ // \ /\/ \__// _ \/ __/ __\ / __/ \ /\/ __/ ___\/ ___\/ \/ \ // __/ / __/ _ \/ \__// __/
| |\ || | ||| |\/|| | //| \ | \/| | | | | ||| \ | \| \| || |\ || | _ | | | / \|| |\/|| \
| | \|| \_/|| | || |_\\| /_| / | |_// \_/|| /_\___ |\___ || || | \|| |_// | |_// |-||| | || /_
\_/ \\____/\_/ \\____/\____\_/\_\ \____\____/\____\____/\____/\_/\_/ \\____\ \____\_/ \|\_/ \\____\
''')
print("Welcome to The Guessing Number Game!\nI am thinking of a whole number between 1 and 100.")
choice = random.randint(1, 100)
print(f"This is a hint to help me debug my programme; the number is: {choice}")
lives = 0
difficulty_level = input("Type 'easy' or 'hard' for the level you want to play: ").lower()
if difficulty_level == "easy":
lives = 10
print(f'You have {lives} guesses to guess right.')
elif difficulty_level == "hard":
lives = 5
print(f'You have {lives} guesses to guess right.')
else:
print(f'Wrong level, please input the right instruction.')
return
continue_guessing = True
while continue_guessing:
player_guess = int(input("Guess the number: "))
if player_guess < choice:
lives -= 1
print(f"Too low!\nGuess again\nYou have {lives} live(s) left.")
elif player_guess > choice:
lives -= 1
print(f"Too high!\nGuess again\nYou have {lives} live(s) left.")
elif player_guess == choice:
print(f"You guessed right, that's the number I was thinking about; Congrats!")
continue_guessing = False
if lives != 0:
pass
else:
print("You ran out of guesses, game over!")
continue_guessing = False
play_game()
# wanna_play_again = input("Want to play a guessing number game? (Y/N): ").lower()
# while wanna_play_again == 'y':
# print("Welcome to The Guessing Number Game!\n I am thinking of a whole number between 1 and 100.")
# play_game()
# else:
# pass