Mistake in Making Purchase


Hi guys, need some checks on this...


Error Message: Oops, try again. compute_bill(['apple']) returned 10.5 instead of 2

I thought the code looks legit, but couldn't figure out where went wrong. Please guide me thank you~

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

print compute_bill("apple")


your for loop:

for food in prices:

prices doesn't hold the shopping list. food (the function parameter) does

use the for loop to loop through your shopping list.


Got it! Thanks! :smiley: