Making a purchase


hi all i want to know what does this mean total += what does the (+=) mean and thank you


Hi the += ...

#for example you a variable num
num = 2

and you want to add a number to the variable num you will do

num = num + 7

#Now num is equal to 9

which is the same as

num += 7


oh thank you so much now i can understand it much better :slight_smile:


excuseme, actually there is something i want to say it's i can't understand any thing from A DAY AT THE SUPER MARKET it's very difficult please help . :frowning:


HI can you post your code or create a new topic with your code and a link to the lesson


alright this is my code

stock = {
    "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] = stock(item) - food[item]
    return total

what i realy want to understand is what or where is the variable which referes to the quantity of what the customer bought :frowning:


the problem is in this line:

stock[item] = stock(item) - food[item]

stock(item) is wrong, this would make it a function call, while you access a value for a dictionary which you do by using square brackets (stock[item]), which you do right earlier on this line

When the customer brought an item, you simply want to reduce the stock by one, not by the item.

If more help is required post an updated version of your code


it worked thank you very very very much :slight_smile: