Exercise 12. Stocking Out Error Message


#1


https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/2/3?curriculum_id=4f89dab3d788890003000096#

I keep getting the following error:
"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}"

My output of 5.5 should be correct but I keep getting the same error.


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

stock = {
    "orange": 32,
    "pear": 15,
    "banana" : 6,
    "apple": 0,
}
    
price = {
    "orange": 1.5,
    "pear": 3,
    "banana": 4,
    "apple": 2,
}

# Write your code below!
def compute_bill(shopping_list):
    total = 0
    for n in shopping_list:
        if stock[n] > 0:
            total += price[n]
            stock[n] = stock[n] - 1
    return total

print compute_bill(food)


#2

Hi this part

def compute_bill(shopping_list):

Inside your compute_bill() function you should put food
The same for your for loop

for n in shopping_list:

#3

def compute_bill(food):

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

#4

Not sure if you got past this, but it wants you to remove print compute_bill(food) because they don't want you to actually remove stick from the dictionary.


#5

oh man thank you so much. You're the only one to provide a relevant answer.


#6

better u print shopping list instead of food at last line of ur code
print compute_bill(food)
replace with
print compute_bill(shopping_list)


#7

I agree, it's seems counterintuitive, but in my case it worked well - just remove or comment the "print" part


#8

I'm confused here. I understand that by calling "print compute_bill(food)", we actually decrease the value in the stock. But isn't that EXACTLY what should be happening? When we run through the shopping list, don't we WANT the stock to decrease? I'm confused as to WHY this is an error.