-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9_guessing_number.py
36 lines (29 loc) · 971 Bytes
/
9_guessing_number.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
import random as rand
print("Welcome to the Number Guessing Game!")
print("I am thinking of a number between 1 and 100")
difficulty = input("Please choose a difficulty. Type 'easy' or 'hard': ")
lives = 0
if difficulty == 'easy':
lives = 10
elif difficulty == 'hard':
lives = 5
print(f"You have {lives} attempts remaining to guess the number")
num = rand.randint(1,100)
end_game = False
while end_game == False:
guess = int(input("Make a guess: "))
if guess > num:
lives -= 1
print("Too high")
print("Guess again")
print(f"You have {lives} attempts remaining to guess the number\n")
elif guess < num:
lives -= 1
print("Too low")
print("Guess again")
print(f"You have {lives} attempts remaining to guess the number\n")
elif guess == num:
end_game = True
print("Correct. You win!")
elif lives == 0:
end_game = True