Making a purchase


shopping_list = [“banana”, “orange”, “apple”]

stock = {
“banana”: 6,
“apple”: 0,
“orange”: 32,
“pear”: 15

prices = {
“banana”: 4,
“apple”: 2,
“orange”: 1.5,
“pear”: 3

Write your code below!

def compute_bill(food):
total = 0
for item in food:
total = total + prices[item]
return total

my question is if the variable ‘item’ iterates through the elements in ‘food’, how does it know when to stop because ‘food’ is not defined yet?


food is the function parameter

function only execute when called, you don’t your function

when you decide to call the function, an argument is required (to satisfy function parameter), the value of argument get passed to function parameter.

now food has a value, so it knows when to stop


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.