Steps Into Kilometres

Python for AIMedium+10 XP+10

Steps Into Kilometres

A fitness app needs a step counter. The counting part is general, so it goes in a parent.

Counter (the parent):

  • Counter() takes no values. It sets count to 0.
  • add(amount) adds amount to count.
  • reset() sets count back to 0.

StepCounter (a child of Counter, with no __init__ of its own):

  • distance_km() returns count * 0.0008, rounded to 2 decimal places. (One step is 0.8 metres.)

Then write two functions:

  • walk_distance(walks): make a StepCounter, add each number of steps in the list, and return distance_km().
  • steps_since_reset(before, after): make a StepCounter. Add every number in before, then call reset(), then add every number in after. Return count.

Examples

walks = [1000, 2500]
returns 2.8
before = [500, 700]
after = [300]
returns 300

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run