4 Bio
4 Bio
4 Bio
8. What are the outcomes of the functions shown below? sum(2,4,6) sum([1,2,3])
a) Error, 6 b) 12, Error c) 12, 6 d) Error, Error Answer: a
EXPLANATION: The first function will result in an error because the function sum() is used to find the
sum of iterable numbers. Hence the outcomes will be Error and 6 respectively.
6. The function complex(‘2-3j’) is valid but the function complex(‘2 – 3j’) is invalid. State whether
this statement is true or false. a) True b) False
Answer: a
EXPLANATION: When converting from a string, the string must not contain any blank spaces around
the + or – operator. Hence the function complex(‘2 – 3j’) will result in an error.
6. What is the output of the function shown below? list(enumerate([2,
3]))
a) Error b) [(1, 2), (2, 3)]
c) [(0, 2), (1, 3)] d) [(2, 3)]
Answer: c
EXPLANATION: The built-in function enumerate() accepts an iterable as an argument. The function
shown in the above case returns containing pairs of the numbers given, starting from 0. Hence the output
will be: [(0, 2), (1,3)].