250+ TOP MCQs on Python Math and Answers

Python Developer Questions & Answers on “Mathematical Functions”.

1. 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
Answer: a
Clarification: It returns a tuple with two elements. The first element is the mantissa and the second element is the exponent.

2. What is the result of math.fsum([.1 for i in range(20)])?
a) 2.0
b) 20
c) 2
d) 2.0000000000000004
Answer: a
Clarification: The function fsum returns an accurate floating point sum of the elements of its argument.

3. What is the result of sum([.1 for i in range(20)])?
a) 2.0
b) 20
c) 2
d) 2.0000000000000004
Answer: d
Clarification: There is some loss of accuracy when we use sum with floating point numbers. Hence the function fsum is preferable.

4. What is returned by math.isfinite(float(‘inf’))?
a) True
b) False
c) None
d) error
Answer: b
Clarification: float(‘inf’) is not a finite number.

5. What is returned by math.isfinite(float(‘nan’))?
a) True
b) False
c) None
d) error
Answer: b
Clarification: float(‘nan’) is not a finite number.

6. What is x if x = math.isfinite(float(‘0.0’))?
a) True
b) False
c) None
d) error
Answer: a
Clarification: float(‘0.0’) is a finite number.

7. What will be the output of the following Python code?

>>> -float('inf') + float('inf')

a) inf
b) nan
c) 0
d) 0.0
Answer: b
Clarification: The result of float(‘inf’)-float(‘inf’) is undefined.

  250+ TOP MCQs on Python Strings and Answers

8. What will be the output of the following Python code?

print(math.isinf(float('-inf')))

a) error, the minus sign shouldn’t have been inside the brackets
b) error, there is no function called isinf
c) True
d) False
Answer: c
Clarification: -float(‘inf’) is the same as float(‘-inf’).

9. What is the value of x if x = math.ldexp(0.5, 1)?
a) 1
b) 2.0
c) 0.5
d) none of the mentioned
Answer: d
Clarification: The value returned by ldexp(x, y) is x * (2 ** y). In the current case x is 1.0.

10. 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)
Answer: a
Clarification: The first element is the fractional part and the second element is the integral part of the argument.

developer questions on Python,

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top