-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmini number game project.py
49 lines (39 loc) · 1.2 KB
/
mini number game project.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
41
42
43
44
45
46
47
48
49
import random
print("Welcome to NUMBER GUESSING GAME!!!")
#checking type of input
def is_int(a):
try:
b=int(a)
return b
except ValueError:
return None
while(True):
no=random.randint(0,100)
chances=6
while chances>0:
a=input("Guess a number (from 1-100) : ")
x=is_int(a)
#if x is other than int
if( x is None):
print("Not an Integer.")
#if x is out of range
elif(x>100 or x<0):
print("Invalid Number.")
elif no < x:
print("Too HIGH! Guess a number smaller than ",x)
elif no > x:
print("Too LOW! Guess a number greater than ",x)
elif no==x:
print("Congratulations, You WON!!!")
break
#decrementing and printing chances left
chances=chances-1
print("Tries left :",chances)
#failed
if chances==0:
print("Better luck next time!!")
print("The number is ",no)
#playing again
y=input("Play Again?(Y/N) : ")
if (y=='n'or y=='N') :
break