# Stocking out 'A Day at the Supermarket'

#1

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]
print compute_bill(shopping_list)

Who knows why the code above needs:
stock[item] = stock[item] - 1 ?

I spend a lot of time trying to figure it out,
First, program did not let me pass without that code, but after I renewed the page
it let me pass without 'stock[item] = stock[item] - 1'
without 'stock[item] = stock[item] - 1' it still computed right answer but gave me the random error which is so far from what I called (I called: print compute_bill(shopping_list))
it's gave me 5.5 but did not let me pass.

#2

It is telling the interpreter to subtract one from the stock dictionary.

#3

I know that, but the code works right even without it

#4

You said it works right but gives you an error, meaning it would not pass even on an actual python interpreter

#5

Check what they asked you in order to code: "Ignore whether or not the item you're billing for is in stock."

#6

Sorry, forget what I've written. I was at the previous exercise.

#7

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