-
Hajipur, Bihar, 844101
Python has a built-in math module that gives access to many mathematical functions like square roots, trigonometry, logarithms, rounding, and more.
Before using math functions, you need to import the module:
import math
Function | Description |
---|---|
math.sqrt(x) |
Square root of x |
math.pow(x, y) |
x raised to the power y |
math.floor(x) |
Rounds down to nearest integer |
math.ceil(x) |
Rounds up to nearest integer |
math.pi |
Returns the value of π (3.14159) |
math.e |
Euler's number (2.718...) |
math.fabs(x) |
Absolute value (float) |
math.factorial(x) |
Factorial of x |
import math
print(math.sqrt(16)) # Output: 4.0
print(math.pow(2, 3)) # Output: 8.0
print(math.floor(3.7)) # Output: 3
print(math.ceil(3.2)) # Output: 4
print(math.factorial(5)) # Output: 120
Function | Description |
---|---|
math.sin(x) |
Sine of x (in radians) |
math.cos(x) |
Cosine of x (in radians) |
math.tan(x) |
Tangent of x (in radians) |
math.radians(x) |
Converts degrees to radians |
math.degrees(x) |
Converts radians to degrees |
angle = math.radians(90)
print(math.sin(angle)) # Output: 1.0
Q1. Write a Python program to print the value of math.pi
.
Q2. Write a Python program to find the square root of 121
using math.sqrt()
.
Q3. Write a Python program to raise 3
to the power 4
using math.pow()
.
Q4. Write a Python program to use math.ceil()
on 2.1
and display the result.
Q5. Write a Python program to use math.floor()
on 9.8
and display the result.
Q6. Write a Python program to convert 90
degrees to radians using math.radians()
.
Q7. Write a Python program to find the cosine of 0
radians using math.cos()
.
Q8. Write a Python program to calculate the factorial of 7
using math.factorial()
.
Q9. Write a Python program to find the absolute value of -9.5
using math.fabs()
.
Q10. Write a Python program to convert 3.14
radians to degrees using math.degrees()
.
Q1: Which module provides advanced math functions in Python?
Q2: What does math.sqrt(49) return?
Q3: What is the use of math.floor(5.9)?
Q4: Which constant gives the value of π?
Q5: What does math.pow(2, 4) return?
Q6: What does math.fabs(-4.5) return?
Q7: What is the factorial of 5?
Q8: Which function converts degrees to radians?
Q9: What is math.sin(math.radians(90))?
Q10: What is returned by math.ceil(2.2)?