Is there a fundamental issue with the supermarket/shopping list exercise?


in this exercise, we see that the code proposed by the editor includes a reference to a list called food, whereas there is no list called food.

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 item in food:
if stock[item] > 0:
total = total + prices[item]
stock[item] = stock[item] - 1
return total

There are, however, lists called stock, prices, and shopping_list. Shopping_list, which should be the core of the choice engine is not referenced at all in the code. I don’t understand how this is actually working at all when you run it. Can anyone help me out?

Replace this line with your code. 


Hi @sjgrand,

When you call the compute_bill function in order for it to execute, you will pass it an argument within parentheses. Within the function, the name food will refer to the same object as that argument. For example, if you do this …

print compute_bill(shopping_list)

… then food will refer to the shopping_list object as the function executes.

Wait until the final exercise to call the compute_bill function. Codecademy will complain if you call it in the previous exercise.


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