You have built your own tools, but Python ships with a huge toolbox called the standard library. It is included with every install. You do not need
pip or internet access to use it.Importing modules
# Import the whole module
import math
result = math.sqrt(16)
print(result) # 4.0
# Or import specific names directly
from random import randint
die = randint(1, 6)import math gives you a namespace. You access functions as math.sqrt(). This is clear and avoids name collisions.from random import randint puts the function directly into your file's scope. It is shorter, but if two modules have a function with the same name, it can get confusing.The math module
import math
print(math.pi) # 3.141592653589793
print(math.sqrt(2)) # ~1.414...
print(math.floor(3.9)) # 3 (round down)
print(math.ceil(3.1)) # 4 (round up)floor and ceil are different from the built-in round(). Floor always goes down to the nearest integer. Ceil always goes up.Randomness you can trust
import random
random.seed(42)
print(random.randint(1, 10))
# Run it again with the same seed and get the exact same number.random.seed() sets the starting point of a deterministic sequence. If you do not set a seed, Python starts from a fresh random point (it asks the operating system), and results differ every run.For debugging or tests, always seed so the output is predictable.