Stocking Out


#1



Stocking Out


File "python", line 22
total += prices[key]
^
IndentationError: expected an indented block


What wrong with the line 22 I saw some post wrote total = total + prices[key]
i want to know the difference, thank you.


Replace this line with your code. 

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


#2

total += prices[key] is a shorthand for total = total + prices[key]

you have an indention problem, check the indent of your code


#4

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