Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import random
  2. c = []
  3. for x in range(0,5):
  4. if x not in c:
  5. c.append(random.randint(0,150))
  6. print (c)
  7. c.sort()
  8. print(c)
  9.  
  10. b = int(input("enter the number to be checked if it is on the list"))
  11.  
  12.  
  13. def binarysearch(list,num):
  14. if len(list) == 0:
  15. return False
  16. else:
  17. midpoint = len(list)//2
  18. if list[midpoint] == num:
  19. return True
  20. elif num <= list[midpoint]:
  21. return binarysearch(list[:midpoint], num)
  22. elif num >= list[midpoint]:
  23. return binarysearch(list[midpoint + 1:],num)
  24.  
  25. print (binarysearch(c,b))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement