The math module
18-minute lesson · module-modules-02
You are previewing this course as a guest
Read anything and run any exercise you like. It all runs in your own browser, so nothing here is saved: no XP, no progress, and the AI tutor needs an account. Sign in and your work starts counting.
The math module
18-minute lesson · module-modules-02
- Compute square roots with `math.sqrt`.
- Round down and up with `math.floor` and `math.ceil`.
- Use the constant `math.pi` in a formula.
- Recognize that `math.sqrt` returns a float while floor/ceil return ints.
Source attribution
Status: adapted
How to Think Like a Computer Scientist: Interactive Edition — source · Modules / The math module
Adaptation notes. Reading rewritten in our voice. Worked example computes the area of a circular plaza on the Iowa State campus. Hidden tests check sqrt, the floor/ceil pair, and a formula that uses math.pi.
License notes. Original chapter is GNU FDL 1.3 (Brad Miller, David Ranum, and the upstream Elkner/Downey/Meyers text). No verbatim text reproduced.