Skip to content

Commit 279804a

Browse files
committed
Update Number-Guesser.py
1 parent 94b6c88 commit 279804a

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

Number-Guesser.py

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
import random
2-
import math
1+
import random, math
32

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: "))
64

7-
x = random.randint(lower_limit, upper_limit)
8-
print("\n\tYou'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\tYou have only ",round(math.log(upper_limit-lower_limit+1,2))," chances to guess the integer!\n")
97

108
count = 0
119

1210
while count < math.log(upper_limit - lower_limit + 1, 2):
1311
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!")
2015
break
2116
elif x > guess:
2217
print("You guessed too small!")
@@ -25,4 +20,4 @@
2520

2621
if count >= math.log(upper_limit - lower_limit + 1, 2):
2722
print("\nThe number is %d" % x)
28-
print("\tBetter Luck Next time!")
23+
print("\tBetter Luck Next time!")

0 commit comments

Comments
 (0)