← All lessons

math: mathematics

Sign in · Sign up

Lesson 7.7

The math module has ready-made mathematical operations:

Call What it gives
math.sqrt(16) the root — 4.0
math.pi the number π (no brackets)
math.ceil(4.2) rounds up — 5
math.floor(4.8) rounds down — 4

The root of a negative number raises an error: there is a separate module for those numbers.

The check sets the numbers a and b and a decimal value. Print, in order:

  1. the hypotenuse math.sqrt(a ** 2 + b ** 2);
  2. π;
  3. value rounded up — with math.ceil;
  4. value rounded down — with math.floor.
Hint

math.sqrt(...) is the root, math.ceil rounds up, math.floor rounds down.

A square is ** 2. Build the sum of the squared legs inside sqrt. Print the constant math.pi on its own line, as it is.