Skip to content

Practical exercise

Write a chai recipe function

A function is a recipe you write once and run a hundred times. Today you will write make_chai with three ingredients as inputs, call it for two cups, four cups, and ten cups, and watch the recipe scale on its own. After this you will never copy paste code again.

35 min·practitioner
Mimi the mascot, encouraging you

Now try it

Write a chai recipe function

Stretch

Add a return statement instead of print. Have the function return a dictionary {water, milk, sugar}. Then write a second function shopping_list(cups) that loops over a list of cups counts and totals the ingredients.

Goes into your portfolio

A screenshot of the chai function code, three scaled outputs in the console for 2, 4, and 10 cups, plus one family member's reaction in writing.