# A Day at the Supermarket

#1

Oops, try again. It looks like "banana" is not in your list.
console reads : ['banana', 'orange', 'apple']
None

print grocery list

``````groceries_list = [ "banana", "orange", "apple"]

print groceries_list``````

#2

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

stock = {
"banana": 6,
"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:
total += prices[1]

``return total``

can any one help with this, I don't understand whats wrong. I have checked it against other peoples code keep getting an error Oops, try again. compute_bill(['apple']) resulted in a KeyError: 1

#3

Problem is here:

``total += prices[1]``

You should add to the `total` price of the `item`.

`prices` is a hash. Values are prices of items, and keys are the items. So, for example, to retrieve price of `apple` you can use:

``prices['apple']``

Problem is that `1` is not the valid key because it does not exist in the `prices` hash.

#4

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

this worked for me

#5

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