-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamesolution.py
36 lines (34 loc) · 1.05 KB
/
gamesolution.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
#The best solution for game and it's maximum and minimum attempts list.
import random
games=''
attemptslist=[]
while games=='':
try:
# games=int(input("how many games would you like to play?"))
games=int(10)
except:
print("please select using a number")
for game in range (0,games):
# low=int(input("enter a minimum value"))
# high=int(input("enter a maximum value"))
low=int(1)
high=int(100)
pick=random.randint(low,high)
guess= None
attempts=0
while pick != guess:
guess=int((low+high)/2)
# print(guess)
if guess != pick:
attempts+=1
if guess>pick:
# print("high")
high=guess
else:
# print("low")
low=guess
else:
print("your number is correct, nice!!!, your attempts to guess answers were:",attempts)
attemptslist.append(attempts)
attemptslist.sort()
print(attemptslist)