Editor

The Biggest Climb

Advanced · Stretch · from Python For Loops: Iterate Over Anything with Examples

From the lesson: Python For Loops: Iterate Over Anything with Examples

Imagine you're a teacher with 30 students. You need to print a report card for each one. Would you write 30 separate print statements? Of course not. You'd tell the computer: "for each student, print their report card." That's exactly what a for loop does.

Read the lesson

A hiking app records the height of the path every few minutes. A climb is a stretch of the path where each height is higher than the one before. Write a function biggest_climb(heights) that returns the most height gained in a single climb, or 0 if the path never goes up.

biggest_climb([100, 120, 115, 130, 160, 150])   # 45

Here the path climbs 20 (100 to 120), drops, then climbs 45 (115 to 160). A step to the same height is not a climb, so it ends the climb before it.

Return the answer instead of printing it: Check calls biggest_climb() with its own paths, some of them hidden.

def biggest_climb(heights):
pass
Solution unlocks after your first Check

What Check runs

Your code runs first, then each of these lines, and 5 more that stay hidden. The output must match exactly.

RunsExpected output
biggest_climb([100, 120, 115, 130, 160, 150])45
biggest_climb([500, 400, 300])0

More For Loop exercises

All Python exercises · 50 practice problems · Control Flow quiz