While Python provides us with basic arithmetic functions by default, there may be scenarios when we want to perform more advanced operations. Importing the math module gives us access to a whole number of additional operations such as:

  • math.ceil(): rounds a number up to the nearest integer
  • math.floor(): rounds a number down to the nearest integer
  • math.sqrt(): calculates the square root of a number
  • math.prod(): returns the product of all items in a list
  • math.factorial(): returns the factorial of a number
  • math.gcd(): returns the greatest common divisor of two integers

Additionally, there are several mathematical constants that may be beneficial:

  • math.pi: 3.141592….
  • math.e: 2.7182….

There are many more functions and constants within the module that may support more complex mathematical calculations, which you can explore here.

Replit Practice