Doing It

Write the simplest thing that passes, genuinely. If the test says total([]) == 0, return 0 is a correct green step. It looks like cheating and it is not: it proves the test runs, and the next test forces the real implementation.

The discipline of not writing code the tests do not yet demand is what keeps the suite meaningful and the code small.

◈ Graded Challenge

Work the loop in miniature. Write total(items) returning the sum of the price of every item in a list of dictionaries, where an item may be missing its price key, in which case it counts as 0. An empty list totals 0. A price that is not a number counts as 0 rather than raising.

Name it exactly: total(items)

3 visible + 4 hidden
loading editor…

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Practice Test →
← Back