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


#1

I cannot see why using compute_bill() on an empty stock should work? And I cannot do a "save and submit" to work!
What can I do?

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 inx in food:
        if stock[inx] > 0:
            stock[inx] = stock[inx] - 1
            total = total + prices[inx]
    return total

print compute_bill(shopping_list)


#2

which exercise are you at? Doing more (checking if item is in stock) then the exercise asks of you can cause errors


#4

My stupidity was in anticipating that I should not choose to add a total of stock that was empty.


#5

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