Advertisement
here2share

# bot_number_guessing.py

Mar 19th, 2025
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. # bot_number_guessing.py
  2. # for ai pattern recognition
  3.  
  4. def guess_the_number(n, target):
  5.     low, high = 1, n
  6.     while low <= high:
  7.         mid = (low + high) // 2
  8.         print(f"My guess is: {mid}")
  9.         if mid == target:
  10.             print("Found it!")
  11.             return mid
  12.         elif mid < target:
  13.             print("Too low!")
  14.             low = mid + 1
  15.         else:
  16.             print("Too high!")
  17.             high = mid - 1
  18.  
  19. n = 10000
  20. target_number = 723
  21. guess_the_number(n, target_number)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement