-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuesser.py
More file actions
88 lines (65 loc) · 2.25 KB
/
Guesser.py
File metadata and controls
88 lines (65 loc) · 2.25 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from random import randint
def random_guessing():
low_limit = 1
high_limit = int(input("Enter the higher limit for the choice: "))
guess = randint(low_limit, int(high_limit))
count, answer = 0, 0
while answer != 3:
count += 1
print("My guess is: ", guess)
answer = int(input("Is that (1) Too High? (2) Too Low (3) Bang on! "))
if answer == 1:
high_limit = guess - 1
if high_limit == 1:
guess = 0
else:
guess = randint(low_limit, high_limit)
elif answer == 2:
low_limit = guess + 1
guess = randint(low_limit, high_limit)
elif answer == 3:
print("Yippee! I guessed your number in ", count, "tries.")
print("You chose ", guess)
else:
print("Terminating. You entered some random shit!")
repeat = input("Would you like to play again? (Y)es or (N)o: ")
if repeat.lower() == "y":
random_guessing()
else:
exit()
def algo_guessing():
low_limit = 1
high_limit = int(input("Enter the higher limit for the choice: "))
guess = (low_limit + high_limit) // 2
count, answer = 0, 0
while answer != 3:
count += 1
print("My guess is: ", guess)
answer = int(input("Is that (1) Too High? (2) Too Low (3) Bang on! "))
if answer == 1:
high_limit = guess - 1
guess = (low_limit + high_limit) // 2
elif answer == 2:
low_limit = guess + 1
guess = (low_limit + high_limit) // 2
elif answer == 3:
print("Yippee! I guessed your number in ", count, "tries.")
print("You chose ", guess)
else:
print("Terminating. You entered some random shit!")
repeat = input("Would you like to play again? (Y)es or (N)o: ")
if repeat.lower() == "y":
random_guessing()
else:
exit()
def main():
gtype = int(input('''Do you want to try
(1)random
(2)algorithm guessing? '''))
if gtype == 1:
random_guessing()
elif gtype == 2:
algo_guessing()
else:
print("Invalid input")
main()