Give a Calculation a Name
A function packages a calculation so several orders can use the same rule. Its parameters are names for inputs. return sends a result back. An if branch chooses what to do under a condition; a for loop processes each item.
Authored explanation · fixed examples, not a live experiment.
Two lines → 6 and 8 credits
→Loop accumulates 14 credits
→One order fee +2 → 16 credits
Where should the fee enter the calculation? Name the evidence for your answer.
By the end of this lesson
Write a function, a branch and a loop with explicit input and output.
Inside the lesson
- Trace a function and loop
- Place the delivery fee
- Implement the fee rule
- Explain the empty case
- Total a different cart
- Keep the function contract
The reproducibility tasks require running the supplied Python starter. Setup instructions and examples are included.