# A day at the supermarket: Making a Purchase

#1

Soooooooo....
When I try to run my shopping list-bill adding machine, it gives a mysterious 7.5 instead of my expected output of 2...

Here is the link to the one I am stuck on:

So once again, when I run the code, codeacademy tells me that:
Oops, try again. compute_bill(['apple']) returned 7.5 instead of 2

and I have no idea where it got 7.5 from, I expected it to give me 2 (ie 0 + 2).

So here is my code:

``````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 food in shopping_list:
total = total + prices[food]

And idk why it don't work!

#2

Here look at my code, I will explain what you did wrong:

``````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 item in food:
total += prices[item]

Look at your Compute_bill function and compare it with me. You should put `for item in food`.

Try that. It works right? Message me if you need anymore help!

~Candy

#3

Thanks Candy, works great!

#4

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