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 brings in the whole module. You reach its tools with a dot, as in math.sqrt(). This is clear, and its names can't clash with yours.from random import randint brings in just that one name, so you write randint() with no dot. 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 rounds down to the whole number below. Ceil always rounds up to the one above.Randomness you can trust
import random
random.seed(42)
print(random.randint(1, 10))
# Same seed, same number, every time you run it.random.seed() sets where the random numbers start, so the same seed always gives the same numbers. 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 testing, seed it so the output is the same every time. In a real game, seed once, or not at all: seeding again with the same seed before every roll gives the same roll every time.