1
0
forked from tdwojak/Python2018
Python2018/labs02/task01.py

29 lines
673 B
Python
Raw Normal View History

2018-05-12 11:37:19 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Zad 2. Napisz funkcję even_elements zwracającą listę,
która zawiera tylko elementy z list o parzystych indeksach.
"""
def even_elements(lista):
2018-05-14 22:30:09 +02:00
result = []
for i in range(len(lista)):
if i % 2 == 0:
result.append(lista[i])
return result
2018-05-12 11:37:19 +02:00
def tests(f):
inputs = [[[1, 2, 3, 4, 5, 6]], [[]], [[41]]]
outputs = [[1, 3, 5], [], [41]]
for input, output in zip(inputs, outputs):
if f(*input) != output:
return "ERROR: {}!={}".format(f(*input), output)
break
return "TESTS PASSED"
if __name__ == "__main__":
print(tests(even_elements))