-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11.Guess-the-number.py
40 lines (32 loc) · 990 Bytes
/
11.Guess-the-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
37
38
39
40
import random
import os
def guess_check():
global CHOSEN_NUMBER,lives
guess = int(input("Make a guess: "))
if guess == CHOSEN_NUMBER:
print(f"You got it! The answer was {CHOSEN_NUMBER}")
quit()
elif guess < CHOSEN_NUMBER:
print("Too Low")
elif guess > CHOSEN_NUMBER:
print("Too High")
print("Guess Again")
lives -= 1
print(f"You have {lives} attempts remaining to guess the number")
os.system('clear')
print("Welcome to the Number Guessing Game.")
print("I\'m thinking of a number between 1 and 100.")
CHOSEN_NUMBER = random.randint(1,100)
while True:
difficulty = input("Choose a difficulty. Type 'easy' or 'hard': ")
if difficulty == 'easy':
lives = 10
break
elif difficulty == 'hard':
lives = 5
break
else:
print("You entered an invalid difficulty level")
while lives > 0:
guess_check()
print(f"You\'ve run out of guesses. The Number was {CHOSEN_NUMBER}")