Making A Purchase


#1



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

    
It Keeps saying "Oops, try again. compute_bill(['apple']) resulted in a KeyError: 1"
I Have No Clue What I Am Doing Wrong. Help Me.


#2

@akapew_22 ,

What's that within the brackets in this line? ...

total = total + prices[1]

#3

yeah that was my mistake, i replaced that with total = total + prices[i]


#4

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