Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- a=[]
- for i in range(10):
- a.append(randint(1, 30))
- a.sort()
- print(a)
- value=int(input("Введите число от 1 до 30: "))
- mid=len(a)//2
- low=0
- high=len(a)-1
- while a[mid]!=value and low<=high:
- if value>a[mid]:
- low=mid+1
- else:
- high=mid-1
- mid=(low+high)//2
- if low >high:
- print("Ненайдено")
- else:
- print("Номер в массиве: ", mid)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement