import
Python · Unit 16: The standard library
- Full plan
- Python
- 10 exercises
Python ships with toolboxes that are already built: modules. There is nothing to download or install, you just ask for them with import.
math is the one for mathematics. Once you import it, you call its functions with the module name in front.
import math
print(math.sqrt(9))
print(math.floor(2.8))Prints
3.0 2
The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Predict the output
What does this code print?
2. Complete the code
Complete it to bring in the module. It should print: 5
3. Find the bug
This program should print the square root of 25. Which line has the error?
4. Predict the output
What does this code print?
5. Multiple choice
You want to write
ceil(2.1)without puttingmath.in front. Which line imports it that way?6. Complete the code
Complete it so the module is called
m. It should print: 37. Predict the output
The area of a circle with radius 2. What does it print?
8. Predict the output
The shop charges every kilo you start. What does it print?
9. Put the lines in order
Put the lines in order to build
hypotenuse(a, b), the long side of a right triangle.10. Find the case that fails
boxes(n)returns how many 6-piece boxes you need to storenpieces: 7 pieces take 2 boxes and 6 pieces fit in 1. Which call breaks it?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.