Problem with the data type (I believe), not sure why my function is taking on a list:


#1



Problem with the data type (I believe), not sure why my function is taking on a list. Please help!


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


#2

This is the list it is taking on, as the argument to the function call:

print compute_bill(shopping_list)

That is if I read this question correctly. Please elaborate. Thank you.

Is this the sticking point? I can see that it would be. We need to query the price so we can add it to the running total.

total += prices[item]

#3

Thank you, the program is now working like a champ! :slight_smile: