Skip to content
CCC Python Course

Floats, precision and big integers

Stage
1
Module
M1.12
Lessons
1

In this module

  • Explain why floats can be slightly off, and avoid comparing them with ==.
  • Scale a calculation to integers to keep output exact.
  • Work with integers of any size, and use math.isqrt instead of math.sqrt for large values.
  • Round a division up with integer ceiling division.

Before this module

Lessons

  1. 1Floats, precision and big integers

Practice

Try these on the judges. Each link opens the problem on WMOJ or DMOJ.

  1. 2021 S1
    Crazy Fencing (opens on WMOJ in a new tab) WMOJ

    Add up trapezoid areas measured from a list of heights and widths.

  2. 2020 S1
    Surmising a Sprinter's Speed (opens on DMOJ in a new tab) DMOJ

    Find the top speed a sprinter must have reached, given a series of timed positions.

    Why DMOJ: An early Senior problem, included here for extra practice.