Python Multiple Choice Questions – Math

This set of Python Objective Questions & Answers focuses on “Math”.

1. What is returned by math.ceil(3.4)?
a) 3
b) 4
c) 4.0
d) 3.0
View Answer

Answer: b
Explanation: The ceil function returns the smallest integer that is bigger than or equal to the number itself.

2. What is the value returned by math.floor(3.4)?
a) 3
b) 4
c) 4.0
d) 3.0
View Answer

Answer: a
Explanation: The floor function returns the biggest number that is smaller than or equal to the number itself.

3. What will be the output of print(math.copysign(3, -1))?
a) 1
b) 1.0
c) -3
d) -3.0
View Answer

Answer: d
Explanation: The copysign function returns a float whose absolute value is that of the first argument and the sign is that of the second argument.
advertisement
advertisement

4. What is displayed on executing print(math.fabs(-3.4))?
a) -3.4
b) 3.4
c) 3
d) -3
View Answer

Answer: b
Explanation: A negative floating point number is returned as a positive floating point number.

5. Is the output of the function abs() the same as that of the function math.fabs()?
a) sometimes
b) always
c) never
d) none of the mentioned
View Answer

Answer: a
Explanation: math.fabs() always returns a float and does not work with complex numbers whereas the return type of abs() is determined by the type of value that is passed to it.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. What is the value returned by math.fact(6)?
a) 720
b) 6
c) [1, 2, 3, 6]
d) error
View Answer

Answer: d
Explanation: NameError, fact() is not defined.

7. What is the value of x if x = math.factorial(0)?
a) 0
b) 1
c) error
d) none of the mentioned
View Answer

Answer: b
Explanation: Factorial of 0 is 1.
advertisement

8. What is math.factorial(4.0)?
a) 24
b) 1
c) error
d) none of the mentioned
View Answer

Answer: a
Explanation: The factorial of 4 is returned.

9. What will be the output of print(math.factorial(4.5))?
a) 24
b) 120
c) error
d) 24.0
View Answer

Answer: c
Explanation: Factorial is only defined for non-negative integers.
advertisement

10. What is math.floor(0o10)?
a) 8
b) 10
c) 0
d) 9
View Answer

Answer: a
Explanation: 0o10 is 8 and floor(8) is 8.

More MCQs on Python Math:

Sanfoundry Global Education & Learning Series – Python.

To practice all objective questions on Python, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.