Please help: also what does += and -= mean


#1

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

#2

they are shorthands, to increase or decrease a variable value:

x = 5
# update variable
x = x + 5
# same, but using shorthand
x += 5

#3

thanks for the help. :slight_smile:


#4

what about the code. I Am very confused


#5

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

#6

it looks alright, what is the problem?


#7

it says

Oops, try again. stock doesn't look quite right! Make sure to not call compute_bill since it changes the stock! It should contain: {'orange': 32, 'pear': 15, 'banana': 6, 'apple': 0}


#8

remove this line:

print compute_bill(shopping_list)

calling the function will change the stock before exercise validition can run, its in the error message


#9

thanks for the help. cant believe I missed that


#10