12. Stocking Out


#1

Can anybody help me here please ? I keep getting this error message:

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

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

#2

Do you need a review of Python syntax? If you do not understand this error then that is what is suggested. What is the error?


#3

mtf said it already, but in the code

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

indent yo


#4

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!


#5

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