Python Math

Built-in functions and the math module.

✍️ 3 exercises + code challenge in this lesson

Built-in maths functions: min(), max(), abs(), pow(), round(), sum().

The math module adds many more:

  • math.sqrt(), math.ceil(), math.floor()
  • math.pi, math.e
  • math.factorial(), math.gcd()
  • Trigonometry: math.sin(), math.cos(), math.radians()

Key Takeaways: Python Math

Mastering Python Math helps you write clean and reliable Python code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

Python Math Code Example

Python
import math

print(min(5, 10, 25), max(5, 10, 25), abs(-7.25), pow(2, 5))
print(math.sqrt(81), math.ceil(1.2), math.floor(1.8))
print("Circle area r=3:", round(math.pi * 3 ** 2, 2))
print("10! =", math.factorial(10))
print("gcd(48, 18) =", math.gcd(48, 18))
Free sign-in required · Google login available

Python Math Practice Exercises

Check what you learned in “Python Math”.

/ 3 solved
Fill in the blank

Round 4.2 up to 5.

math.(4.2)
✓ Correct! Not quite. Try again.
Multiple choice

What does abs(-7) return?

✓ Correct! Not quite. Try again.
Code challenge

Print the smallest and largest of 8, 3, 15 separated by a space using min() and max().

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services