-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumberguessing.py
More file actions
29 lines (26 loc) · 822 Bytes
/
Copy pathnumberguessing.py
File metadata and controls
29 lines (26 loc) · 822 Bytes
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
import random
print("welcome to number guessing game\n")
n=random.randint(1,100)
game_over=False
chances=0
def level_choosing():
level=input("Choose the difficulty level\nEnter 'easy' for easy level\nEnter 'difficult' for difficult level\n\n>>>")
if level=="easy":
l_n=10
else:
l_n=5
return l_n
level_n=level_choosing()
for _ in range(level_n):
chances+=1
g=int(input("Guess the number : "))
if g>n:
print(f"Guess a small number than {g}")
elif g<n:
print(f"Guess a large number than {g}")
elif g==n:
print(f"YES... you guessed the correct number ,that is, {g}\nThe number of chance taken {chances}")
break
print(f"number of chances left : {level_n-chances}")
if chances==level_n:
print(f"you lost\nThe number was {n}")