-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
Introduction to Python
Python Basics
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Casting
Python I/O
Python Operators
Cotrol Structures
Data Structures
Python Strings
Python Lists
Python Tuples
Python Dictionaries
Python Sets
Python Arrays
Python Bytes and Bytearray
Date and Time
Functions and Module
File Handling
Python OOP
Advanced Concepts
Python Scope
Python Modules
Python JSON
Python RegEx
Python PIP
Python Try...Except
Python String Formatting
Python User Input
Python VirtualEnv
Python Math
Python DSA
Python DSA
Lists and Arrays
Python Stacks
Python Queues
Linked Lists
Python Hash Tables
Python Trees
Python Binary Trees
Binary Search Trees
Python AVL Trees
Python Graphs
Searching Algorithms
Sorting Algorithms
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()
.
Introduction to Python
Python Basics
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Casting
Python I/O
Python Operators
Cotrol Structures
Data Structures
Python Strings
Python Lists
Python Tuples
Python Dictionaries
Python Sets
Python Arrays
Python Bytes and Bytearray
Date and Time
Functions and Module
File Handling
Python OOP
Advanced Concepts
Python Scope
Python Modules
Python JSON
Python RegEx
Python PIP
Python Try...Except
Python String Formatting
Python User Input
Python VirtualEnv
Python Math
Python DSA
Python DSA
Lists and Arrays
Python Stacks
Python Queues
Linked Lists
Python Hash Tables
Python Trees
Python Binary Trees
Binary Search Trees
Python AVL Trees
Python Graphs
Searching Algorithms
Sorting Algorithms