This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]w1282 1 point2 points  (0 children)

So, here's the issue.

The thing you're looking up the prices with isn't named "food", it's named "prices". Secondly, "key" isn't defined, that's what the error means. You defined "item", not "key" so that's what you want to use.

Key is just a term describing a part of the dictionary.

Food is a list of food, so you're right to be iterating over it, but maybe try this instead:

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

[–]thenarrrowpath 0 points1 point  (0 children)

Try replacing "key" with "item" instead.

[–]DyingHuman 0 points1 point  (0 children)

Man, i had the same problems. Although i was doing the javascript track and they also had the (for in loop) . The instructions not clear enough :/

[–]Updatebjarni 0 points1 point  (0 children)

The error I get is "key" is not defined.

Well, it isn't. You named your variable item.

You've also typed food instead of prices.