Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # bot_number_guessing.py
- # for ai pattern recognition
- def guess_the_number(n, target):
- low, high = 1, n
- while low <= high:
- mid = (low + high) // 2
- print(f"My guess is: {mid}")
- if mid == target:
- print("Found it!")
- return mid
- elif mid < target:
- print("Too low!")
- low = mid + 1
- else:
- print("Too high!")
- high = mid - 1
- n = 10000
- target_number = 723
- guess_the_number(n, target_number)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement