Lesson 43 / 47

random & math

Generate randomness and reach for common mathematical functions.

random & math

random picks, shuffles, and samples; math covers square roots, trig, constants and more than the built-in operators can.

import random, math

print(random.randint(1, 6))       # a dice roll
print(random.choice(["a", "b", "c"]))
print(math.sqrt(2))
print(math.pi)