Getting Error


#1

Trying to solve "Stocking Out" #12

My code is :

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 n in food:
        if stock[n]>0:
            p=prices[n]
            print p
        total=total+p
        else:
            print "Item is not in stock"
    return total
    stock[n]=stock[n]-1

Screen showing an error :

File "python", line 25
else:
^
SyntaxError: invalid syntax

Anybody plz suggest, what wrong with else statement and anything wrong with the code(logical)...


#2

this line:

total=total+p

is not correctly indented. You don't need else?


#3

Still not working....

for n in food:
if stock[n]>0:
p=prices[n]
print p
total=total+p
print total


#4

you never reduce the stock? Once a customer has bought an item, we need to update/reduce our stock


#5

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