3 Лаба пайтон-11405001182545405547(1)
.docxМіністерство освіти і науки
ВСП технічний коледж національного унівеститету “львівська політехніка”
Лаболаторна робота №3
з предмету: Алгоритми та МО
Студента групи 31КІ
Ковальського Володимира
Викладач:
НазаркевичюМ.А
Львів 2019
Варіант4
1
>>>L = [6, 0, 3, 8, 2, 9, 1, 3, 5, 7]
l = []
K = []
for n in L:
if n <= 5 and n >= 1:
l.append(n)
for b in L:
if b >= 6 and b <= 10:
K.append(b)
>>>for m in l:
print(l.index(m))
for v in K:
print(K.index(v))
2B
a=[1, 4, 8, 10 ]
value = int(input())
8
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("Index =", mid)
Index = 2
2A
a=[1,2,8,10]
def Line(alist, item):
pos = 0
found = False
while pos < len(alist) and not found:
if alist[pos] == item:
found = pos
else:
pos = pos+1
return found
print(Line(a, 8))
2