PythiloLesson 29 of 30 · progress kept in this browser

math and random

The math module holds the usual functions for numbers, and random makes pseudo-random choices.

import math

print(math.sqrt(16), math.pi)
print(math.floor(2.7), math.ceil(2.1))
print(math.hypot(3, 4))      # 5.0
print(math.dist((0, 0), (1, 1)))
print(math.prod([2, 3, 4]))  # 24

math.floor rounds down and math.ceil rounds up, and both return an int. math.dist measures a straight line between two points.

Your task

Write roll_dice(n, seed) returning a list of n six-sided die rolls made with its own random.Random(seed), without touching the shared generator. Write distance(a, b) returning the straight-line distance between two (x, y) points.