special python programs By Hashir Ahmad
1. Guessing game program
import random
l=0
h=100
g=0
num=(random.randint(l,h))
bt=True
try:
while (bt):
inp=(input(f'enter guess between ({0}-{h}) or q to exit: '.title())).lower()
if (inp)=='q':
print('Have a good time...')
bt = False
elif int(inp)> num:
print('too high'.title())
g+=1
continue
elif int(inp) < num:
print('tooo low number'.title())
g+=1
continue
else:
print('correct!!!!!'.upper())
print(f'it took you {g} guesses'.capitalize())
num=(random.randint(l,h))
except ValueError :
print('invalid input')
Comments
Post a Comment