Week 2

Nutrition Facts

A lookup table from a fruit to a number. A long chain of choices is the hard way.

You type

A fruit.

The tool
A name opens a number fruits one fruit a number
What comes out

A calorie number, or silence when the fruit is not in the table.

The question, more slowly

The question is: a fruit comes in, and if it is one of the fruits on the FDA poster, you print its calories. If it is not, you print nothing. Matching ignores capitalization. The names are the ones on the poster, so a plural stays plural.

A dict from fruit to calories is the right shape. A long chain of conditionals will work and will be miserable. Look the name up. If it is there, print the number. If it is not, do not print a zero.

People print calories from fat instead of the calorie total, or they store the fruit with one capitalization and forget to normalize the input. The spec points at the poster.

Before you code

Make a tiny table of three fruits you invent and look one up with your finger. The spec has the real table.