# 11. Making a Purchase

#1

I've been trying for a while to pass 11. Making a purchase but I don't know what's wrong with my code. Could some help me out please!!!!?!?

def compute_bill(food):
total = 0
for key in food:
total += prices[key]

#2

hi your code is fine its maybe a indent problem here how its should be..

``````def compute_bill(food):
total = 0
for key in food:
total += prices[key]

#3

Thank you it works!!!

#4

Hello, I have two questions:

1) I'm sorry but what does the += mean?

2) Would you be willing to provide some feedback on the following?
def compute_bill(food):
total = 0
for n in food:
d = total + prices[key]
print d

#5

Here's an example to understand it:

`total = total + 12`

is the same as

`total += 12`

#6

HI its a way to add something to another value like that
`num = num + 1` its can also be that `num += 1`.

the intructuion say
Define a function `compute_bill` that takes one argument`food` as input.

`def compute_bill(food)`

In the function, `create a variable` `total`with an initial value of`zero.`

``````def compute_bill(food):
total= 0``````

`For each item` in the food list, `add the price` of `that item to total`.

``````def compute_bill(food):
total= 0
for key in food:
total = total + price[key]``````

instead of `key` you can choose any other word ......and `price` should be `add to the total` with the word you choose in the `for loop`. in my case `key`

and then you should `return the total`

``````def compute_bill(food):
total= 0
for key in food:
total = total + price[key]

#7

Thank you frozen T, much appreciated.

#8

Hi Wiz, thank you for the feedback! messed around with the code some more and it seems that having key in the for-loop is necessary for the code to work, though I don't understand why. I thought that compute_bill was a list and would not have keys as a dictionary would have....

I got the code to work so thank you for your help!

#9

jeez, thanks a lot

#10

def compute_bill(food):
total = 0
for item in food:
total = total + prices[item]