Codington
0 of 6 problems solved • 0%

Exercise prompt

Count the Rungs

An accumulator starts at a known value and changes once per step. The sum of the first three positive integers is 1 + 2 + 3.

Example

Print the stops for a three-floor lift.

highest_floor = 3 for floor in range(1, highest_floor + 1): print(f"Floor {floor}") # Floor 1 # Floor 2 # Floor 3

The stop value of a range is excluded. Adding one makes the top floor part of the trip. The same range can supply numbers for a calculation.

Your task

Complete rung_total(top) by adding the integers from 1 through top. When top is zero the total is zero. Try writing it with a for loop.

rung_total(4) # 10