Guess the number
v1.1
import random
a=random.randint(1,20)
t=1
print('Guess the number between 1-30\nYou have total 4 chance')
while True:
print('-------------\nchance =>',t,'\n------------- ')
g=int(input('Enter number\n-------------\n'))
if g>a:
print('=>Decrease the number')
elif g<a:
print('=>Increase the number')
elif g==a:
print('You find the number')
break
t=t+1
if t==5:
print('!!Time up!!\nCorrect answer:',a)
break
v1.2
import random
a=random.randint(1,20)
t=4
print('Guess the number in 4 chances')
print('Number is between 1-20\nChance left => ',t)
while t>0:
u=int(input('Guess the number: '))
t=t-1
if t==0:
print('!Time up!\nCORRECT ANSWER => ',a)
break
if u==a:
print('You find the number')
break
if t==1:
print('--Last chance--')
if u<a:
print('Your number is smaller','\nChance left => ',t)
if u>a:
print('Your number is greater','\nChance left => ',t)
v1.3
import random
a=random.randint(1,20)
t=4
print('Guess the number in 4 chances')
print('Number is between 1-20\nChance left => ',t)
while t>0:
try:
u=int(input('Guess the number: '))
t=t-1
if u==a:
print('You find the number')
break
if t==1:
print('--Last chance--')
if u<a:
print('Your number is smaller','\nChance left => ',t)
if u>a:
print('Your number is greater','\nChance left => ',t)
if t==0:
print('!Time up!\nCORRECT ANSWER => ',a)
break
except Exception as E:
print(E)