Learn with Yasir

Share Your Feedback

Python Math Module Review Questions – Key Concepts & Functions Explained


Master Python's math module with these comprehensive review questions covering constants, rounding, trigonometric functions, logarithms, and numerical checks like isfinite(), isinf(), and more. Ideal for coding exams and interviews.

🔍 Review Questions

  1. What is the purpose of the `math` module in Python?

  2. Answer

    The `math` module provides access to mathematical functions defined by the C standard.

    
    
    

    📘 Related Topics:


  3. How do you import the `math` module in Python?

  4. Answer

    You can import the `math` module using `import math`.

    
    
    

    📘 Related Topics:


  5. What is the difference between `math.floor()` and `math.ceil()`?

  6. Answer

    `math.floor()` returns the largest integer less than or equal to the number, while `math.ceil()` returns the smallest integer greater than or equal to the number.

    
    
    

    📘 Related Topics:


  7. What values do `math.pi` and `math.e` represent?

  8. Answer

    `math.pi` represents the value of π (approximately 3.14159) and `math.e` represents Euler’s number (approximately 2.71828).

    
    
    

    📘 Related Topics:


  9. What is the output of `print(math.tau)`?

  10. Answer

    It prints the value of τ (tau), which is 2π or approximately 6.28318.

    
    
    

    📘 Related Topics:


  11. What does `math.pow(x, y)` return, and how is it different from `x ** y`?

  12. Answer

    `math.pow(x, y)` returns x raised to the power y as a float, while `x ** y` may return an int if both x and y are integers.

    
    
    

    📘 Related Topics:


  13. How do you compute the square root of a number using the `math` module?

  14. Answer

    Use `math.sqrt(x)` to compute the square root of x.

    
    
    

    📘 Related Topics:


  15. What is the difference between `math.log(x)` and `math.log10(x)`?

  16. Answer

    `math.log(x)` returns the natural logarithm (base e) of x, while `math.log10(x)` returns the base-10 logarithm of x.

    
    
    

    📘 Related Topics:


  17. What is the output of `math.exp(2)`?

  18. Answer

    It returns e raised to the power 2, approximately 7.389.

    
    
    

    📘 Related Topics:


  19. What is the output of `math.sin(math.pi / 2)`?

  20. Answer

    It returns 1.0.

    
    
    

    📘 Related Topics:


  21. Which function would you use to convert radians to degrees?

  22. Answer

    Use `math.degrees(x)` to convert radians to degrees.

    
    
    

    📘 Related Topics:


  23. How do you convert 180 degrees to radians using the `math` module?

  24. Answer

    Use `math.radians(180)`, which returns π radians.

    
    
    

    📘 Related Topics:


  25. What does `math.fabs(x)` do?

  26. Answer

    It returns the absolute value of x as a float.

    
    
    

    📘 Related Topics:


  27. When would you use `math.factorial(x)`?

  28. Answer

    When you need the factorial of a non-negative integer x.

    
    
    

    📘 Related Topics:


  29. What’s the result of `math.isqrt(10)`?

  30. Answer

    It returns the integer square root of 10, which is 3.

    
    
    

    📘 Related Topics:


  31. What does `math.isfinite(x)` check for?

  32. Answer

    It checks whether x is neither infinite nor NaN.

    
    
    
    
    

  33. How is `math.isnan(x)` different from `math.isinf(x)`?

  34. Answer

    `math.isnan(x)` checks if x is NaN, while `math.isinf(x)` checks if x is positive or negative infinity.

    
    
    
    
    

  35. Write a Python function that returns the ceiling, floor, and rounded value of a float using the `math` module.

  36. Answer

    Use `math.ceil(x)`, `math.floor(x)`, and `round(x)` respectively.

    
    
    

    📘 Related Topics:


  37. What will happen if you pass a negative number to `math.sqrt()`? How can you handle it?

  38. Answer

    It raises a `ValueError`. You can handle it using a `try-except` block or use the `cmath` module for complex results.

    
    
    

    📘 Related Topics:


  39. Identify and correct the error in the following code: `math.sqrt(-16)`

  40. Answer

    The code raises a `ValueError` because the square root of a negative number is not defined in the real domain. Use `cmath.sqrt(-16)` instead.

    
    
    

    📘 Related Topics: