The Podium

The big moment: the three heaviest pumpkins step onto the podium. Finish the program with the line Podium: and the three winners below it, starting with the heaviest pumpkin:

Ribbons: 1 gold, 2 silver, 1 bronze
Podium:
1. Grandpa Joe (31 kg)
2. Anna (27 kg)
3. Tom (25 kg)

When fewer than three pumpkins are entered, the podium has fewer places. With only Lily's and Hugo's pumpkins, the program prints just 1. Hugo (18 kg) and 2. Lily (12 kg).

A tip: you already know how to find the heaviest pumpkin. Once it has its place on the podium, it no longer competes: take it out of both lists, and the next heaviest pumpkin is the heaviest one left. And math.min can tell you how many places the podium has.

That's the whole project. Your program goes through the lists, adds up, counts and finds the heaviest pumpkins, all with loops, lists and conditions. In the next lesson, on functions, you'll learn to give a piece of code a name and use it again whenever you need it. The search for the heaviest pumpkin, which the program now does in two places, could then be written just once.

Instructions

Print the podium: the three heaviest pumpkins, starting with the heaviest.

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

3/3