×

python · level 2 · unit 5 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

borrows a full of ready-made tools.

Python comes with hundreds of modules, together called the . Each module is a toolbox for one job: maths, dates, chance, files and more. Nobody has to write a square root function twice.

Write import math at the top of your program. Then reach inside with a dot: math.sqrt(81) is the square root of 81, and math.pi is pi.

math.ceil rounds up to the next whole number and math.floor rounds down, which helps when you cannot buy half a box.

import math
print(math.sqrt(81))
print(math.pi)
guests = 23
per_table = 6
print(math.ceil(guests / per_table))
print(math.floor(7.9))

Put every import at the top, so readers can see which toolboxes you use.