-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumber-Guesser.py
More file actions
29 lines (24 loc) · 775 Bytes
/
Number-Guesser.py
File metadata and controls
29 lines (24 loc) · 775 Bytes
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
import random, math
lower_limit, upper_limit = int(input("Enter Lower Limit: ")), int(
input("Enter Upper Limit: ")
)
x = random.randint(lower_limit, upper_limit)
print(
"\n\tYou have only ",
round(math.log(upper_limit - lower_limit + 1, 2)),
" chances to guess the integer!\n",
)
count = 0
while count < math.log(upper_limit - lower_limit + 1, 2):
count += 1
guess = int(input("Guess a number: "))
if x == guess:
print("Congratulations! You did it in", count, "tries!")
break
elif x > guess:
print("You guessed too small!")
elif x < guess:
print("You Guessed too high!")
if count >= math.log(upper_limit - lower_limit + 1, 2):
print("\nThe number is %d" % x)
print("\tBetter Luck Next time!")