class Finder:
def __init__(self):
self.current_range = range(1, 101)
def condition(self, user_select):
if user_select == '1':
return True
elif user_select == '2':
self.current_range = range(int(self.current_half + self.current_range.start), self.current_range.stop)
return False
elif user_select == '3':
self.current_range = range(self.current_range.start, int(self.current_half + self.current_range.start))
return False
@property
def current_half(self) -> int:
return int((self.current_range.stop - self.current_range.start) / 2)
finder = Finder()
while True:
user_select = input(f'Это {finder.current_half + finder.current_range.start}?\n')
result = finder.condition(user_select)
if result:
break
import random
right_ans = int(input('Введите число от 1 до 100: '))
a = 1
b = 101
right = False
tries = 1
while not right:
comp_answer = random.randint(a, b)
if comp_answer > right_ans:
b = comp_answer
elif comp_answer < right_ans:
a = comp_answer + 1
else:
print(f'Yes, thats it, computer guessed with {tries} attempts')
right = True
tries += 1