Making a purchase


This is my code:

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): 
    for item in food:
        total += prices[item]
    return total
print compute_bill(shopping_list)

Why do I get this massage my code is wrong? "Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 9 instead of the correct 7",
even if the output seems right: 7.5

thank's, Shirley


You're calling compute_bill on shopping_list, but you define the contents of shopping_list wrong. Try correcting that.


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