your function is wrong as in food argument you should pass a list of your shopping items, so when you do a for loop on it it should be as:for item in food:so your item is an each element on your shopping list so with that item you fetch prices: total += prices[item]I think now it should work