The Weigh-In

Time for another project! This checkpoint puts the loops and lists from the last two lessons to work, together with everything you learned before them. As in the first checkpoint, the instructions say what the program should print, and how you write it is up to you. And as there, each exercise also runs your program with other data, so it has to work everything out from the lists at the top.

The project. Every autumn, the village holds a pumpkin fair, and the heaviest pumpkin wins. This year, Emma has entered one too. Over three exercises, your program will weigh in the pumpkins, give them ribbons and announce the three winners.

The data. The pumpkins are in two lists. growers holds the names of the people who grew them, and weights their weights in kilograms. Items with the same index belong together: growers[2] is Grandpa Joe, and his pumpkin weighs weights[2], 31 kg. The exercise also tries other pumpkins, and more or fewer of them, so get the number of pumpkins from the list, don't write 6 into your code.

The task. Print how many pumpkins there are, their average weight with one decimal place, and the heaviest pumpkin with the name of its grower. For these pumpkins, the program prints:

Pumpkins: 6
Average: 22.7 kg
Heaviest: Grandpa Joe (31 kg)

The heaviest pumpkin can be anywhere in the list, the first and the last item included. No two pumpkins weigh the same, so there's always just one heaviest.

A tip: remember the pattern for the largest value from the lesson on lists, and how you kept its index too, so that you could find the name of the day in another list.

Instructions

Print how many pumpkins there are and their average weight, with one decimal place.

Below that, print the heaviest pumpkin and who grew it.

Start programming for free

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

Or sign up with:

1/3