Stocking Out: PLEASE HELP


#1


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


This is my code so far but this lesson is realllllllllly confusing me. Can someone please explain this to me? TNX


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:
            stock[item] -= 1
        total = prices[item] + total
    return total


#2

you are pretty close, but there is one small problem here:

total = prices[item] + total

only if the item is in stock, should you increase the total, you can charge customers for products that are not in stock


#3

So how should i change my code?


#4

already mentioned this:

what determines if the item is in stock? And how could we make sure total is only increased when item is in stock?


#7

Add an indent before the total = prices[item] + total and your code will work


#8

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