Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. from random import randint
  2. a=[]
  3. for i in range(10):
  4. a.append(randint(1, 30))
  5. a.sort()
  6. print(a)
  7.  
  8.  
  9. value=int(input("Введите число от 1 до 30: "))
  10.  
  11. mid=len(a)//2
  12. low=0
  13. high=len(a)-1
  14.  
  15. while a[mid]!=value and low<=high:
  16. if value>a[mid]:
  17. low=mid+1
  18. else:
  19. high=mid-1
  20. mid=(low+high)//2
  21.  
  22. if low >high:
  23. print("Ненайдено")
  24. else:
  25. print("Номер в массиве: ", mid)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement