-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumber Guessing Game without GUI.py
More file actions
60 lines (53 loc) · 1.78 KB
/
Number Guessing Game without GUI.py
File metadata and controls
60 lines (53 loc) · 1.78 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
import random
high_score=0
def user_choice():
score=0
print("Number Guessing Game")
level=input("Choice Level: easy, medium or hard: ").lower()
if level not in ["easy","medium","hard"]:
print("Invalid level")
return
if level=="easy":
random_num=random.randint(0,5)
heart=5
welcome=print(f"your heart are {heart}❤")
elif level=="medium":
random_num=random.randint(0,10)
heart=3
welcome=print(f"your heart are {heart}❤")
elif level=="hard":
random_num=random.randint(0,50)
heart=3
welcome=print(f"your heart are {heart}❤")
def game():
global score
global heart
global high_score
while True:
try:
num=int(input("Your answer: "))
except ValueError:
print("Please enter a number")
continue
if num==random_num:
score+=1
high_score=score
print("You're right 🎉")
print(f"Thanks for playing!The number was {random_num} and the high score was {high_score}. Goodbye <3 ")
break
elif num<random_num:
heart-=1
print(f"Too Low, Your hearts are {heart}❤ ")
elif num>random_num:
heart-=1
print(f"Too High, Your hearts are {heart}❤")
if heart ==0:
print("You failed")
ques=input("Do you want to play again? Y/N: ").upper()
if ques=="Y":
user_choice()
else:
print(f"Thanks for playing!The number was {random_num} and the score was {score} and the high score was {high_score}.Goodbye and see you again!")
break
game()
user_choice()