Stocking Out 12 correct code not passed


#1



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

Receive this error message: Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 69 instead of the correct 7

correct computation of total price


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 item in food:
        if stock[item]>0:
            total += prices[item] * stock[item]
            stock[item]-=stock[item]
    return total


#2

are you sure about this line:

total += prices[item] * stock[item]

The moment your order one item, you pay the price of the item * number of items in stock.

No need to multiply it, just add the price of the item to the total:

total += prices[item]

#3

Oops, it seems i was hasty with my answer, now this line:

stock[item]-=stock[item]

the moment your order one item, the whole stock is sold out. I would just subtract one:

stock[item] -= 1

I like your business plan, the moment a customer buys one item, give them the entire stock of that item and make them pay for it, it makes good money :slight_smile: (in case it wasn't obvious, that was just a little joke )