Python script to automate binary search