-
Hajipur, Bihar, 844101
Python gives you many ways to work with numbers, from simple arithmetic to advanced calculations. The language includes built-in operators for everyday math, and it also provides a special module named math that contains functions for square roots, powers, rounding, constants and trigonometry. Whether you are building a billing tool, a scientific program or a data-processing script, these features help you work with numbers correctly and efficiently.
In this tutorial, you will learn how Python handles numbers, how arithmetic works, how to use the math module, how to apply common functions and how to use constants like pi. Each concept is explained with clear examples so you can use them in your programs immediately.
Python supports basic mathematical operations using symbols that work just like a calculator.
a = 10
b = 5
print(a + b)
print(a - b)
print(a * b)
print(a / b)
Division always returns a float, even if the result is a whole number.
Floor division removes the decimal part and gives the result as a whole number.
print(10 // 3)
This is useful when you want to calculate items per box, pages per file or anything where you need whole units.
The modulus operator gives the remainder.
print(10 % 3)
This is often used in:
Checking even or odd numbers
Finding cycle patterns
Building timing or scheduling programs
You can raise numbers to a power using **.
print(2 ** 3)
This is helpful for calculations such as interest, growth or any repeated multiplication.
Python has a built-in module called math that contains many useful mathematical functions. To use it, you need to import it first:
import math
This module includes functions for square roots, trigonometry, logarithms, rounding and more.
The sqrt() function returns the square root of a number.
import math
print(math.sqrt(25))
This is commonly used in geometry, physics and data science.
You can calculate power using math.pow() as well.
print(math.pow(2, 4))
It always returns a float, even if the result is a whole number.
Python provides several helpful rounding functions.
print(round(3.5678, 2))
This rounds a number to the nearest value with the specified number of decimals.
ceil() rounds up, while floor() rounds down.
import math
print(math.ceil(3.2))
print(math.floor(3.8))
These are helpful when calculating pages, seats or any situation where you need whole numbers.
Absolute value removes the sign and keeps the number positive.
print(abs(-15))
Useful for distances, differences or measurements.
The math module provides functions for sine, cosine and tangent.
import math
print(math.sin(0))
print(math.cos(0))
print(math.tan(0))
Angles must be in radians. You can convert degrees to radians using:
math.radians(90)
log() gives the natural logarithm.
import math
print(math.log(10))
You can also use base-10 log:
print(math.log10(100))
These are often used in scientific and statistical work.
The math module provides predefined constants.
print(math.pi)
print(math.e)
These constants help in geometry, trigonometry and growth calculations.
You can find the smallest or largest value easily.
nums = [5, 10, 2, 8]
print(min(nums))
print(max(nums))
This helps in grading systems, scores and data comparisons.
Python has a built-in function for adding all numbers in a list.
nums = [10, 20, 30]
print(sum(nums))
This is useful in billing tools, salary calculations or total marks.
When input is received from a user, it is often a string. You can convert it using:
int("10")
float("5.7")
This lets you perform calculations on user-entered values.
price = 250.75
qty = 3
total = price * qty
print(round(total, 2))
import math
r = 4
area = math.pi * r * r
print(area)
p = 5000
r = 5
t = 2
si = (p * r * t) / 100
print(si)
f = 98.4
c = (f - 32) * 5/9
print(c)
import math
x1, y1 = 3, 4
x2, y2 = 7, 1
dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
print(dist)
Add two numbers
10 + 5
Find remainder
10 % 4
Floor division
25 // 4
Power
3 ** 4
Square root
math.sqrt(36)
Round decimal
round(4.678, 1)
Round up
math.ceil(4.2)
Round down
math.floor(4.9)
Convert degrees
math.radians(180)
Find maximum
max([2, 7, 9])
Python gives you a complete set of tools for working with numbers. You learned basic arithmetic, power, floor division and modulus. You also explored the math module, which includes square roots, rounding functions, logarithms, trigonometric functions and constants like pi and e. These tools help you build reliable calculations for real programs such as billing apps, scientific tools, scoring systems and data analysis tasks. With regular practice, you will understand when to use built-in operators and when to rely on the math module for more precise results.
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().