-
Notifications
You must be signed in to change notification settings - Fork 0
/
gussNumber.py
36 lines (27 loc) · 883 Bytes
/
gussNumber.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
import random
import math
try:
min = int(input('Enter min range:- '))
max = int(input('Enter max range:- '))
count = 0
x = random.randint(min, max)
times = round(math.log(max - min + 1, 2))
print('\n\t\tYou have only ', times,'changes')
except:
print ('Invalid ranges have been entered.\nThus the program is being terminated.')
else:
while count < times:
count += 1
guess = int(input('Guess a number:- '))
if x == guess:
print('Congratulations you did it in ',
count, ' try')
break
elif x > guess:
print('You guessed too small!')
else:
print('You Guessed too high!')
if count >= times:
print('\n\tThe guess number is %d' % x)
finally:
print ('\t\tThank You\n\tFor Playing the Game')