Making a Purchase


I am stuck at "A Day in the SuperMarket", specifically on "Making a Purchase"

I am getting the error - "Oops, try again. computebill(['apple']) returned 1.5 instead of 2_"

It should be printing "2"

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

print compute_bill(shopping_list)

Any Ideas?


Let me explain what your function compute_bill() does..
The parameter of your compute_bill() function is food.
food is nothing but can be a random list of fruits.
Whenever someone gives a random list of fruits as argument,we loop through it and using our prices dictionary we add the price to total and return it.

I hope it helps.


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