Test Series - python

Test Number 79/108

Q: What does the function math.frexp(x) return?
A. a tuple containing the mantissa and the exponent of x
B. a list containing the mantissa and the exponent of x
C. a tuple containing the mantissa of x
D. a list containing the exponent of x
Solution: It returns a tuple with two elements. The first element is the mantissa and the second element is the exponent.
Q: What is the result of math.fsum([.1 for i in range(20)])?
A. 2.0
B. 20
C. 2
D. 2.0000000000000004
Solution: The function fsum returns an accurate floating point sum of the elements of its argument.
Q: What is the result of sum([.1 for i in range(20)])?
A. 2.0
B. 20
C. 2
D. 2.0000000000000004
Solution: There is some loss of accuracy when we use sum with floating point numbers. Hence the function fsum is preferable.
Q: What is returned by math.isfinite(float(‘inf’))?
A. True
B. False
C. None
D. error
Solution: float(‘inf’) is not a finite number.
Q: What is returned by math.isfinite(float(‘nan’))?
A. True
B. False
C. None
D. error
Solution: float(‘nan’) is not a finite number.
Q: What is x if x = math.isfinite(float(‘0.0’))?
A. True
B. False
C. None
D. error
Solution: float(‘0.0’) is a finite number.
Q: What is the value of x if x = math.ldexp(0.5, 1)?
A. 2.0
B. 1
C. 0.5
D. none of the mentioned
Solution: The value returned by ldexp(x, y) is x * (2 ** y). In the current case x is 1.0.
Q: What is returned by math.modf(1.0)?
A. (0.0, 1.0)
B. (1.0, 0.0)
C. (0.5, 1)
D. (0.5, 1.0)
Solution: The first element is the fractional part and the second element is the integral part of the argument.

You Have Score    /8