-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessnumber_game.py
More file actions
73 lines (61 loc) · 2.25 KB
/
Guessnumber_game.py
File metadata and controls
73 lines (61 loc) · 2.25 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
61
62
63
64
65
66
67
68
69
70
71
72
73
import random
def choose_difficulty():
while True:
difficulty = input("Enter your difficulty\n1 for Easy\n2 for Medium\n3 for Hard\n>>>")
if not difficulty.isdigit():
print("Invalid input,Plz select 1,2,3 only")
continue
difficulty = int(difficulty)
if difficulty not in [1,2,3]:
print("Invalid input,Plz select 1,2,3 only")
continue
if difficulty == 1:
a = -1
r = random.randint(1,100)
while(a != r):
a = input("Guess a number bteween 1 to 100:")
if not a.isdigit():
print("Invalid input")
continue
if int(a) > r:
print("wrong ans! Try a lower number")
elif int(a) < r:
print("wrong ans! Try a higher number")
else:
print("Right answer!")
break
elif difficulty == 2:
r = random.randint(1,200)
a = -1
while(a != r):
a = input("Guess a number between 1 to 200:")
if not a.isdigit():
print("Invalid input")
continue
if int(a) > r:
print("wrong ans! Try a lower number")
elif int(a) < r:
print("wrong ans! Try a higher number")
else:
print("Right answer!")
break
elif difficulty == 3:
r = random.randint(1,300)
a = -1
while(a != r):
a = input("Guess a number between 1 to 300:")
if not a.isdigit():
print("Invalid input")
continue
if int(a) > r:
print("wrong ans! Try a lower number")
elif int(a) < r:
print("wrong ans! Try a higher number")
else:
print("Right answer!")
break
else:
print("Invalid choices")
break
choose_difficulty()
# Making it more intresting