1
- import random
2
- import math
1
+ import random , math
3
2
4
- lower_limit = int (input ("Enter Lower Limit Number:- " ))
5
- upper_limit = int (input ("Enter Upper Limit Number:- " ))
3
+ lower_limit ,upper_limit = int (input ("Enter Lower Limit: " )),int (input ("Enter Upper Limit: " ))
6
4
7
- x = random .randint (lower_limit , upper_limit )
8
- print ("\n \t You've only " ,round (math .log (upper_limit - lower_limit + 1 , 2 ))," chances to guess the integer!\n " )
5
+ x = random .randint (lower_limit , upper_limit )
6
+ print ("\n \t You have only " ,round (math .log (upper_limit - lower_limit + 1 , 2 ))," chances to guess the integer!\n " )
9
7
10
8
count = 0
11
9
12
10
while count < math .log (upper_limit - lower_limit + 1 , 2 ):
13
11
count += 1
14
- guess = int (input ("Guess a number:- " ))
15
- if x == guess and count == 1 :
16
- print ("Congratulations! You did it in 1 try!" )
17
- break
18
- if x == guess and count > 1 :
19
- print ("Congratulations! You did it in " ,count ," tries!" )
12
+ guess = int (input ("Guess a number: " ))
13
+ if x == guess :
14
+ print ("Congratulations! You did it in" ,count ,"tries!" )
20
15
break
21
16
elif x > guess :
22
17
print ("You guessed too small!" )
25
20
26
21
if count >= math .log (upper_limit - lower_limit + 1 , 2 ):
27
22
print ("\n The number is %d" % x )
28
- print ("\t Better Luck Next time!" )
23
+ print ("\t Better Luck Next time!" )
0 commit comments