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.
The `math` module provides access to mathematical functions defined by the C standard.
📘 Related Topics:
You can import the `math` module using `import math`.
📘 Related Topics:
`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:
`math.pi` represents the value of π (approximately 3.14159) and `math.e` represents Euler’s number (approximately 2.71828).
📘 Related Topics:
It prints the value of τ (tau), which is 2π or approximately 6.28318.
📘 Related Topics:
`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:
Use `math.sqrt(x)` to compute the square root of x.
📘 Related Topics:
`math.log(x)` returns the natural logarithm (base e) of x, while `math.log10(x)` returns the base-10 logarithm of x.
📘 Related Topics:
It returns e raised to the power 2, approximately 7.389.
📘 Related Topics:
It returns 1.0.
📘 Related Topics:
Use `math.degrees(x)` to convert radians to degrees.
📘 Related Topics:
Use `math.radians(180)`, which returns π radians.
📘 Related Topics:
It returns the absolute value of x as a float.
📘 Related Topics:
When you need the factorial of a non-negative integer x.
📘 Related Topics:
It returns the integer square root of 10, which is 3.
📘 Related Topics:
It checks whether x is neither infinite nor NaN.
📘 Related Topics:
`math.isnan(x)` checks if x is NaN, while `math.isinf(x)` checks if x is positive or negative infinity.
📘 Related Topics:
Use `math.ceil(x)`, `math.floor(x)`, and `round(x)` respectively.
📘 Related Topics:
It raises a `ValueError`. You can handle it using a `try-except` block or use the `cmath` module for complex results.
📘 Related Topics:
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: