Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- c = []
- for x in range(0,5):
- if x not in c:
- c.append(random.randint(0,150))
- print (c)
- c.sort()
- print(c)
- b = int(input("enter the number to be checked if it is on the list"))
- def binarysearch(list,num):
- if len(list) == 0:
- return False
- else:
- midpoint = len(list)//2
- if list[midpoint] == num:
- return True
- elif num <= list[midpoint]:
- return binarysearch(list[:midpoint], num)
- elif num >= list[midpoint]:
- return binarysearch(list[midpoint + 1:],num)
- print (binarysearch(c,b))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement