jootiee

Untitled

Nov 26th, 2021 (edited)
236
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. from math import ceil
  3. clear = lambda: os.system('cls' if os.name == 'nt' else 'clear')
  4.  
  5. n = int(input())
  6. guess = 0
  7. numbers = [1, n]
  8.  
  9. def pprint(n):
  10.     print("?", n)
  11.     # print("\n")
  12.     # clear()
  13.  
  14. def make_a_guess():
  15.     number = (numbers[0] + numbers[1]) / 2
  16.     if int(number) == float(number):
  17.         number = int(number) + 1
  18.     else:
  19.         number = ceil(number)
  20.     return number
  21.  
  22.  
  23.  
  24.  
  25.  
  26. guess = make_a_guess()
  27. pprint(guess)
  28. while True:
  29.     x = input()
  30.    
  31.     if x == "<":
  32.         numbers[1] = guess - 1
  33.     elif x == "<=":
  34.         numbers[1] = guess
  35.     elif x == ">":
  36.         numbers[0] = guess - 1
  37.     elif x == ">=":
  38.         numbers[0] = guess
  39.    
  40.     guess = make_a_guess()
  41.  
  42.     if len(set(numbers)) == 1:
  43.         print("!", numbers[0])
  44.         break
  45.     pprint(guess)
RAW Paste Data