# Stocking Out Problem

#1

Having trouble with the Stocking Out exercise.

When I run the code I get the following message:
Oops, try again. stock doesn't look quite right! Make sure to not call compute_bill since it changes the stock! It should contain: {'orange': 32, 'pear': 15, 'banana': 6, 'apple': 0}

Here are the instructions which seems to conflict with the Oops message:
1. 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.
2. If the item is in stock and after you add the price to the total, subtract one from the item's stock count.

What gives? Why is this code not acceptable? Please, help

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

print compute_bill(shopping_list)``````

What gives? Why is this not acceptable?

#2

Make sure to not call compute_bill since it changes the stock!

Your code is calling the function.

#3

OMG ... I get it now.

#4

Coincidently I wrote same code as t0ny.fr33man had written. I saw your response but didn't get what you are trying to convey to correct the code. Please help.

#5

Make sure to not call compute_bill since it changes the stock!

#6

Comment out the print line. The instructions do not say to call the code.

#7

Wow, that was not intuitive. You want to make the function, but you do not want to go "shopping" AKA comment out the print statement

#8

Ii is indicative of how important it is to read and understand the instructions, and to follow them.

#9

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