Test Series - python

Test Number 61/108

Q: What will be the output of the following Python functions?

chr(‘97’)
chr(97)
A.  a Error
B.  ‘a’ a
C. Error a
D. Error Error
Solution: The built-in function chr() returns the alphabet corresponding to the value given as an argument. This function accepts only integer type values. In the first function, we have passed a string. Hence the first function throws an error.
Q: What will be the output of the following Python function?

complex(1+2j)
A. Error
B. 2
C. 2j
D. 1+2j
Solution: The built-in function complex() returns the argument in a complex form. Hence the output of the function shown above will be 1+2j.
Q: What is the output of the function complex()?
A. 0j
B. 0+0j
C. Error
D. 0
Solution: The complex function returns 0j if both of the arguments are omitted, that is, if the function is in the form of complex() or complex(0), then the output will be 0j.
Q: The function divmod(a,b), where both ‘a’ and ‘b’ are integers is evaluated as:
A. (a%b, a//b)
B. (a//b, a%b)
C. (a//b, a*b)
D. (a/b, a%b)
Solution: The function divmod(a,b) is evaluated as a//b, a%b, if both ‘a’ and ‘b’ are integers.
Q: What will be the output of the following Python function?

divmod(10.5,5)
divmod(2.4,1.2)
A. (2.00, 0.50) (2.00, 0.00)
B. (2, 0.5) (2, 0)
C. (2.0, 0.5) (2.0, 0.0)
D. (2, 0.5) (2)
Solution: See python documentation for the function divmod.
Q: The function complex(‘2-3j’) is valid but the function complex(‘2 – 3j’) is invalid.
A. True
B. False
C. none
D. ...
Solution: 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.
Q: What will be the output of the following Python function?

list(enumerate([2, 3]))
A. Error
B. [(1, 2), (2, 3)]
C. [(0, 2), (1, 3)]
D. [(2, 3)]
Solution: 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)].
Q: Which of the following functions does not necessarily accept only iterables as arguments?
A. enumerate()
B. all()
C. chr()
D. max()
Solution: The functions enumerate(), all() and max() accept iterables as arguments whereas the function chr() throws an error on receiving an iterable as an argument. Also note that the function chr() accepts only integer values.

You Have Score    /8