Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. list = [2, 10, 14, 23, 45 ,56, 64, 74, 86,90]
  2. length = len(list)
  3. number = int(input("What number are you searching for? "))
  4.  
  5. LowerBound = 0
  6. UpperBound = length - 1
  7. match = False
  8.  
  9. while match == False and LowerBound ?? UpperBound:
  10. MidPoint = (LowerBound + UpperBound) // 2
  11. if list[MidPoint] == number:
  12. print("We have found your number!")
  13. match == True
  14. break
  15. elif list[MidPoint] < number:
  16. LowerBound = MidPoint + 1
  17. else:
  18. UpperBound = MidPoint - 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement