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 lessonA 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]) # 45Here 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.
What Check runs
Your code runs first, then each of these lines, and 5 more that stay hidden. The output must match exactly.
| Runs | Expected output |
|---|---|
| biggest_climb([100, 120, 115, 130, 160, 150]) | 45 |
| biggest_climb([500, 400, 300]) | 0 |
More For Loop exercises
- Print the Shopping ListBeginner
- Sum Numbers 1 to 10Beginner
- Predict the OutputBeginner
- Fix the Bug: Letter CounterBeginner
- Numbered MenuBeginner
- Reverse a StringBeginner
- Student Grade ReportBeginner
All Python exercises · 50 practice problems · Control Flow quiz