11. Problems at checkout (Haha... market jokes...)

#1

``````See code below. Question wants a total of the products being purchase.
The code below yields the correct number (7.5), but Im getting this as an error message:
Oops, try again. compute_bill(['apple']) returned 7.5 instead of 2

shopping_list = ["banana", "orange", "apple"]

stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}

def compute_bill(food):
total=0
for n in shopping_list:
total+=prices[n]

#2

Looking around, I found the solution to my problem.

"shopping_list" in the for loop should have been listed as "food".
I understand that "food" is the argument, but I do not know where food was defined so that I could use it in the function.

If anyone knows, an explanation would be appreciated! Thanks in advance!

#3

Use the parameter variable so other arguments may be passed in. Note that `prices['apple']` is `2`.

#4

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