Stocking Out - stuck on this one


#1



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

I'm stuck on this one and not sure what is wrong. Why would it want to return 2 instead of 0. There are no apples so it should be o, right?


Error message:

Oops, try again. compute_bill(['apple']) returned 0 instead of 2


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

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

# Write your code below!

def compute_bill(food):
    total = 0
    for produce in food:
        if stock[produce] > 0:
            total += prices[produce]
            stock[produce] -= 1
    return total


#2

Instruction:

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

so now it doesn't ignore that.

we just need total price of any food list. we don't need to check whether it is in stock or not.


#3

There is no issue with the code i copied it and pasted it into my editor and it allowed me to pass to the next stage


#4

It still returns the same error. What Ih ad to do for some buggy reason is to change the quantity of apple in the beginning lists


#7

can you please post the update version of your code?


#8

Any solution for this? Please let's help out gurus in the house!


#9

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