FUNCTIONS -1
1. Which
of the following functions is a built-in function in python?
a) max() b) sqrt() c) sum() d)
print()
Answer: d
Explanation: The function seed is a function which is present in the random module. The functions sqrt and factorial are a part of the math module. The print function is a built-in function which prints a value directly to the system output.
2. What
is the output of the expression:
round(7.587)
a) 4.5 b) 8 c) 4 d)
4.6
Answer: b
Explanation:
This is a built-in function which rounds a
number to give precision in decimal digits. In the above case, since the number
of decimal places has not been specified, the decimal number is rounded off to
a whole number. Hence the output will be 8.
3. The
function pow(a,b,c) is evaluated as:
a)
(a**b)**c b) (a**b) / c
c) (a**b)
% c d) (a**b)*c
Answer: c
Explanation: The built-in function pow() can accept two or three arguments. When it takes in two arguments, they are evaluated as: a**b. When it takes in three arguments, they are evaluated as: (a**b)%c.
4. What
is the output of the function shown below?
all([2,4,0,6])
a) Error b) True c) False d)
0
Answer: c
Explanation:
The function all returns false if any one of
the elements of the iterable is zero and true if all the elements of the
iterable are non zero. Hence the output of this function will be false.
5. What
is the output of the expression?
round(5.5676,2)?
a) 4.5 b) 4.6 c) 5.57 d) 4.56
Answer: c
Explanation: The function round is used to round off the given decimal number to the specified decimal places. In this case the number should be rounded off to two decimal places. Hence the output will be 5.57.
6. What
is the output of the following function?
any([2>8,
4>2, 1>2])
a) Error b) True c) False d)
4>2
Answer: b
Explanation:
The built-in function any() returns true if
any or more of the elements of the iterable is true (non zero), If all the elements
are zero, it returns false.
7. What
is the output of the function shown below?
import
math
abs(math.sqrt(49))
a) Error b) 9 c) -6 d) 7.0
Answer: d
Explanation: The abs() function prints the absolute value
of the argument passed. For example: abs(-7)=7. Hence , in this case we get
abs(7.0)=7.0.
8. What
are the outcomes of the functions shown below?
sum(3,5,7)
sum([2,3,4])
a) Error, 9 b) 15, Error c) 15, 9 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 9 respectively.
9. What
is the output of the function:
all(3,0,4.2)
a) True b) False c) Error d)
0
Answer: c
Explanation: The function all() returns ‘True’ if any one
or more of the elements of the iterable are non zero. In the above case, the
values are not iterable, hence an error is thrown.
10. What
is the output of the functions shown below?
min(max(False,-3,-4),
2,7)
a) 2 b) False c)
-3 d) -4
Answer: b
Explanation:
The function max() is being used to find the
maximum value from among -3, -4 and false. Since false amounts to the value
zero, hence we are left with min(0, 2, 7) Hence the output is 0 (false).