1 Answers
π Quick Study Guide: Python Math Functions
- π‘ The `math` module in Python provides access to many standard mathematical functions and constants.
- βοΈ `math.sqrt(x)`: Returns the square root of `$x$`. For example, `math.sqrt(9)` is `$3.0$`.
- π’ `math.pow(x, y)`: Returns `$x$` raised to the power of `$y$`. Equivalent to `$x^y$`. For instance, `math.pow(2, 3)` is `$8.0$`.
- β¬οΈ `math.floor(x)`: Returns the largest integer less than or equal to `$x$`. Example: `math.floor(4.7)` is `$4$`, `math.floor(-3.2)` is `$-4$`.
- β¬οΈ `math.ceil(x)`: Returns the smallest integer greater than or equal to `$x$`. Example: `math.ceil(4.1)` is `$5$`, `math.ceil(-3.9)` is `$-3$`.
- π `math.fabs(x)`: Returns the absolute value of `$x$` as a float. Similar to `abs()` but always returns a float. Example: `math.fabs(-5)` is `$5.0$`.
- π `math.log(x, base)`: Returns the logarithm of `$x$` to the given `base`. If `base` is not specified, it defaults to the natural logarithm (base `$e$`). Example: `math.log(100, 10)` is `$2.0$`.
- π Trigonometric Functions: `math.sin(x)`, `math.cos(x)`, `math.tan(x)` take `radians` as input. `math.radians(degrees)` converts an angle from degrees to radians.
- π `math.pi`: The mathematical constant `$\pi$` (approximately `$3.14159$`).
- π `math.e`: The mathematical constant `$e$` (approximately `$2.71828$`).
π§ Practice Quiz: Python Functions for Mathematical Calculations
Choose the best option for each question.
Question 1:
Which Python `math` module function is used to calculate the square root of a number?
- π΅ A) `math.power()`
- π’ B) `math.root()`
- π‘ C) `math.sqrt()`
- π£ D) `math.square()`
Question 2:
What will be the output of `math.floor(4.7)`?
- π΅ A) 4
- π’ B) 5
- π‘ C) 4.0
- π£ D) 5.0
Question 3:
Which of the following expressions correctly calculates $2^3$ using the `math` module?
- π΅ A) `math.power(2, 3)`
- π’ B) `math.pow(2, 3)`
- π‘ C) `math.exp(2, 3)`
- π£ D) `math.exponent(2, 3)`
Question 4:
To get the natural logarithm (base $e$) of 10, which function would you use?
- π΅ A) `math.log10(10)`
- π’ B) `math.log(10, math.e)`
- π‘ C) `math.ln(10)`
- π£ D) `math.log(10)`
Question 5:
What is the result of `math.ceil(-3.2)`?
- π΅ A) -3
- π’ B) -4
- π‘ C) 3
- π£ D) 4
Question 6:
If you want to convert an angle of 90 degrees to radians before using a trigonometric function, which `math` module function should you use?
- π΅ A) `math.degrees_to_radians(90)`
- π’ B) `math.rad(90)`
- π‘ C) `math.radians(90)`
- π£ D) `math.convert_to_radians(90)`
Question 7:
Which function from the `math` module returns the absolute value of a number?
- π΅ A) `math.abs()`
- π’ B) `math.absolute()`
- π‘ C) `math.value()`
- π£ D) `math.fabs()`
Click to see Answers
1. C
2. A
3. B
4. D
5. A
6. C
7. D
Join the discussion
Please log in to post your answer.
Log InEarn 2 Points for answering. If your answer is selected as the best, you'll get +20 Points! π