Compute_bill(['apple']) returned 63.5 instead of 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
def compute_bill(food):
    total =0
    for food in prices:
        print food
        print "stock: %s " % stock[food]
        print "prices: %s " %prices[food]
        both = float(stock[food]) + float(prices[food])
        print "both: %s" % both
        total= total+both
        print total
    return total


What do you think the right outcome for ['apple'] is? What should be done with that input, what steps should be carried out?
You've already got a whole lot of prints in your function, if you call your function with the same input as your error message mentions, what do the prints tell you that it is doing differently from what it should be doing?


Check this,hope it helps


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