22 - python & all web labs
This commit is contained in:
36
labPython/lab21/task_4.py
Normal file
36
labPython/lab21/task_4.py
Normal file
@@ -0,0 +1,36 @@
|
||||
class SimpleIter4:
|
||||
def __init__(self, data):
|
||||
self.data = data
|
||||
self.result = []
|
||||
evens = [data[i] for i in range(0, len(data), 2)][::-1]
|
||||
odds = [data[i] for i in range(1, len(data), 2)]
|
||||
self.result = evens + odds
|
||||
self.index = 0
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
if self.index >= len(self.result):
|
||||
raise StopIteration
|
||||
val = self.result[self.index]
|
||||
self.index += 1
|
||||
return val
|
||||
|
||||
|
||||
while True:
|
||||
print("1 - Ввести список")
|
||||
print("0 - Выход")
|
||||
choice = input("Выбор: ")
|
||||
|
||||
if choice == "0":
|
||||
break
|
||||
|
||||
if choice == "1":
|
||||
try:
|
||||
data = input("Введите элементы через пробел: ").split()
|
||||
it = SimpleIter4(data)
|
||||
for x in it:
|
||||
print(x)
|
||||
except:
|
||||
print("Ошибка")
|
||||
Reference in New Issue
Block a user