Cumulative Elevation Gain Calculator


In mountaineering, running or cycling the cumulative elevation gain (aka total ascent) refers to the sum of every gain in elevation throughout an entire trip.

Note that when calculating this elevation gain, elevation losses are not counted in this measure.

When evaluating the difficulty of a hike, you should consider both the total distance of the hike as well as its cumulative elevation gain. Effectively, hiking 10 kilometres on flat land is significantly easier than hiking up and down a series of high peaks over the same distance.

In this challenge, we are going to write a Python script to help a hiker plan their journey by estimating the cumulative elevation gain of their planned hike.

Your Python script will need to:

  • Ask the user to enter the altitude of the starting point of the trip,
  • For each peak or pit on the planned journey, ask the user to enter the altitude of the peak/or peat,
  • Automatically add-up all the corresponding elevation gains (and ignore elevation losses!)
  • Output the cumulative elevation gain of the planned hike!

Python Challenge

Your challenge is to complete the Python code below…

Test Plan

Test # Input Values Expected Output Actual Output
#1 Starting Altitude: 1800m
1st Peak: 2100m
1st Pit: 1950m
2nd Peak: 2240m
Ending Altitude: 1800m
Cumulative Elevation Gain: 590m
#2 Starting Altitude: 1500m
1st Peak: 1850m
1st Pit: 1800m
2nd Peak: 2100m
2nd Pit: 1900m
3rd Peak: 2400m (End of Trek)
Cumulative Elevation Gain: 1150m
#3
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 4.3 / 5. Vote count: 12

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!