forked from gaborbencsik/zerda-exam-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirst.py
More file actions
21 lines (15 loc) · 670 Bytes
/
first.py
File metadata and controls
21 lines (15 loc) · 670 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Create a function that takes a list as a parameter,
# and returns a new list with every second element from the original list.
# It should raise an error if the parameter is not a list.
# Example: with the input [1, 2, 3, 4, 5] it should return [2, 4].
def second_element_function(inputList):
if type(inputList) == list:
return inputList[1::2]
else:
raise TypeError('only list type input accepted!')
testList = [1, 2, 3, 4, 5]
print(second_element_function(testList))
testLongerList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
print(second_element_function(testLongerList))
testFakeList = 'alma'
print(second_element_function(testFakeList))