Codington
0 of 6 problems solved • 0%

Exercise prompt

Charge in Steps

In a while loop, update the value used by the condition on every pass. Check the starting state before counting the first step.

Example

A download removes one full chunk at a time until a partial chunk remains.

remaining = 17 while remaining >= 5: remaining -= 5 print(remaining) # 2

The loop checks 17, 12, 7, and finally 2. At 2 it stops before another subtraction. Decide which battery levels still need another step.

Your task

Complete charge_steps(level, target, gain). Return the smallest number of equal charging steps needed to reach or exceed the target. Gain is a positive integer. An already charged battery needs zero steps.

charge_steps(20, 50, 12) # 3 (32, 44, 56)