Math

The first module we are going to learn is about the math module. Math allows the user to solve almost any mathematical operation.

In this module, we could anything ranging from find simple roots to finding trigonometric equations.

But first, we will have to import this module.

Hence, the first line of the code would be:

import math

In this math.py file, there are various functions created for our convenience and in order to use them, we call those functions from the module. To call them, we place a dot and name the function to use it. Remember that some functions will have to have some parameters passed in. Here is an example of how to find the square root.

math.sqrt(25) 

sqrt is the name of the function where we can find the square root of a given number and the given number is the parameter we will have to pass in the parenthesis.

This function would give us an answer of 5.

Here are some functions that are possible with this module.

math.factorial(x) - Returns the factorial of 'x'
math.fmod(x,y) - Returns the remainder when x is divided by y 
math.exp(x) - Returns e^x 
math.log2(x) - Returns base-2 logarithm of 'x'
math.pi() - Returns the value of 'pi'
math.log10(x) - Returns base-10 logarithm of 'x'
math.pow(x,y) - Returns x to the power of y 
math.cos(x) - Returns cos of x 
math.sin(x) - Returns sin of x 
math.tan(x) - Returns tan of x 
math.gcd(x,y) - Returns the greatest common denominator of x and y
math.radians(x) - Returns the x degrees to radians 
math.degrees(x) - Returns the x radians to degrees 
math.e() - Returns the value of 'e'