Stocking Out


#1



Replace this line with your code.


#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 key in food:
        if (stock[key] >= 0):
            total=total+ prices[key]
            stock[key]=stock[key]-1
    return total
print compute_bill(shopping_list)

#3

help me with this...


#4

your if condition:

if (stock[key] >= 0):

requires improvement. You don't want this to be true when the stock equals zero. use >, this way only if there is actually something in stock, the if condition runs

Don't call the function, the checking script has difficulty's with this


#8

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