All challenges

Saturday, 19 September 2026

Past

Three rungs, one idea. Solving rung 1 counts. Climb as far as you can.

Who Has The Most

dictionaries + comparing values

Rung 1Daily goal5 points

Count all the marbles

Write a function called total_marbles

bag is a dictionary where each key is a name and each value is how many marbles that person has. Return how many marbles everybody has altogether. An empty dictionary returns 0.

Examples

InputOutput
{"ana": 3, "bo": 4}7
{}0
{"ana": 5}5
{"ana": 0, "bo": 0}0

There are extra hidden tests, so make it work in general, not just for these.

Rung 2Bonus7 points

Who has the most

Write a function called most_marbles

Same dictionary. Return the name of the person with the most marbles. If two people have the same number, return the one that appears first in the dictionary. An empty dictionary returns None.

Examples

InputOutput
{"ana": 3, "bo": 4}"bo"
{"ana": 4, "bo": 4}"ana"
{}None
{"cy": 7}"cy"

There are extra hidden tests, so make it work in general, not just for these.

Rung 3Bonus10 points

The top two

Write a function called top_two

Return a list of the two names with the most marbles, the biggest first. When two people have the same number, the one appearing first in the dictionary goes first. If there is only one person, return a list holding just that name, and an empty dictionary returns an empty list.

Examples

InputOutput
{"ana": 3, "bo": 4, "cy": 1}["bo", "ana"]
{"ana": 2}["ana"]
{}[]
{"ana": 5, "bo": 5, "cy": 5}["ana", "bo"]

There are extra hidden tests, so make it work in general, not just for these.

Finish Rung 1 and today counts. Rungs 2 and 3 are there if you want to push further.