last lab
This commit is contained in:
43
labPython/lab16/task_3.py
Normal file
43
labPython/lab16/task_3.py
Normal file
@@ -0,0 +1,43 @@
|
||||
class Node:
|
||||
def __init__(self, data):
|
||||
self.data = data
|
||||
self.next = None
|
||||
|
||||
|
||||
def build(arr):
|
||||
head = None
|
||||
for x in reversed(arr):
|
||||
node = Node(x)
|
||||
node.next = head
|
||||
head = node
|
||||
return head
|
||||
|
||||
|
||||
def find_second(head):
|
||||
count = 0
|
||||
while head:
|
||||
if head.data % 6 == 0:
|
||||
count += 1
|
||||
if count == 2:
|
||||
return head
|
||||
head = head.next
|
||||
return None
|
||||
|
||||
|
||||
while True:
|
||||
try:
|
||||
print("\n1 - создать список")
|
||||
print("2 - найти элемент")
|
||||
print("0 - выход")
|
||||
c = input(">> ")
|
||||
|
||||
if c == "1":
|
||||
arr = list(map(int, input().split()))
|
||||
head = build(arr)
|
||||
elif c == "2":
|
||||
res = find_second(head)
|
||||
print(res.data if res else "nil")
|
||||
elif c == "0":
|
||||
break
|
||||
except:
|
||||
print("Ошибка")
|
||||
Reference in New Issue
Block a user