Python For GCSE
Math Module

Python has some built-in mathematical statements and a built-in module with a load more. These come in useful in all sorts of programs.

Already Available

The following program shows some of the mathematical statements that are automatically available to you without needing to import anything.

small = min(1, 10, 3, 7)
print("The smallest value is", small)

large = max(1, 10, 3, 7)
print("The largest value is", large)

a = abs(-23)
print("The absolute value of -23 is", a)

p = pow(3,4)
print("3 to the power of 4 is", p)

Importing Math

import math

If you import the math module, you get access to a load of other methods. Some of the ones you might use up to GCSE are shown below.

If you use any trigonometric methods, bear in mind that they work with radians instead of degrees. Spend some time learning about how radians work before you use these methods.

math.acos()Returns the arccosine of a numbermath.acos(0.5)
math.asin()Returns the arcsine of a numbermath.asin(0.5)
math.atan()Returns the arctangent of a number in radiansmath.atan(0.5)
math.ceil()Rounds a number up to the nearest integermath.ceil(1.3)
math.comb()Returns the number of ways to choose k items from n items without repetition and ordermath.comb(10, 2)
math.cos()Returns the cosine of a numbermath.cos(0)
math.degrees()Converts an angle from radians to degreesmath.degrees(1)
math.exp()Returns E raised to the power of xmath.exp(10)
math.factorial()Returns the factorial of a numbermath.factorial(5)
math.floor()Rounds a number down to the nearest integermath.floor(12.45)
math.gcd()Returns the greatest common divisor of two integersmath.gcd(16, 4)
math.log()Returns the natural logarithm of a number, or the logarithm of number to basemath.log(2)
math.log10()Returns the base-10 logarithm of xmath.log10(100)
math.log2()Returns the base-2 logarithm of xmath.log2(128)
math.perm()Returns the number of ways to choose k items from n items with order and without repetitionmath.perm(10, 2)
math.radians()Converts a degree value into radiansmath.radians(180)
math.sin()Returns the sine of a numbermath.sin(0)
math.sqrt()Returns the square root of a numbermath.sqrt(16)
math.tan()Returns the tangent of a numbermath.tan(1)
math.trunc()Returns the truncated integer parts of a numbermath.trunc(1.74)

The math module also includes some useful constants. The most useful of these is probably math.pi. Another one you might find a use for is math.tau (which is 2 times pi). Euler's constant can be returned with math.e.