A day at supermarket


def compute_bill(food):
total = 0

for item in food:
    if stock[item] >0:
        total += prices[item]
return total

error is
Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana caused the following error: unhashable type: 'list'

what do i do?


First of all:
Instructions state:

Ignore whether or not the item you're billing for is in stock.

Meaning, you don't need to validate whether the item is in stock or not. Therefore you don't need your if statement at all.
Secondly, stock[food] -= 1 is not the way to decrease stock. As you are trying to do the WHOLE list that is inputted at once and not each item through iteration. The next lesson will tell you how to decrease your stock.


While you loop through each item of food, only add the price of the item to total if the item's stock count is greater than zero.

this is the first condition. so have to use if statement


Oh wait, you ARE on the other lesson. Sorry, I didn't know what lesson you were on so I was guessing here.

Then yea

That's your problem. You're validation is correct with stock[item] which is to validate the stock of an item but why do you use stock[food] when subtracting stock of an item?


thanks got it
:smile: :slight_smile:


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