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

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

What is the Error ???


#2

here:

for item in prices:

you loop over prices, which means you buy one item of each. Read the instructions again, you will need to loop over something else


#3

Did I should loop in stock ?


#4

Define a function compute_bill that takes one argument food as inpu

Note that your function should work for any food list


#5

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