Stocking Out


#1


Help! This function keeps returning some number below or above every time!


shopping_list = ["banana", "orange", "apple"]

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}
    
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
}

def compute_bill(food):
    total = 0
    for x in food:
        if stock[x] > 0:
            total = total + prices[x]
            stock[x]-1
    return total


#3

This is an expression, not a statement. It should read...

stock[x] -= 1

#4

THX. That worked. I didn't know about the = sign. Again, thanx.


#5
a = a - 1

same as,

a -= 1

#6

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