Advertisement
Guest User

Ывык

a guest
Apr 26th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. from random import randint
  2.  
  3.  
  4. def random_list(size=0):
  5.     return list([randint(0, 100) for x in range(size)])
  6.  
  7.  
  8. def bin_search(array, number):
  9.     low = 0
  10.     high = len(a) - 1
  11.     while low <= high:
  12.         mid = (low + high) // 2
  13.         if number < array[mid]:
  14.             high = mid - 1
  15.         elif number > array[mid]:
  16.             low = mid + 1
  17.         else:
  18.             return mid
  19.     else:
  20.         return -1
  21.  
  22.  
  23. n = int(input())
  24. a = random_list(n)
  25. a.sort()
  26. print(a)
  27.  
  28. x = int(input())
  29.  
  30. print(bin_search(a, x))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement