Stocking Out


#1



what is wrong here !?


Replace this line with your code. 
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 key in food:
        if stock[key] > 0 :
        total =  total + prices[key]
        stock[key] = stock[key] -1
    return total


#2

you should indent after a if statement:

if stock[key] > 0 :
total =  total + prices[key] # missing indent
stock[key] = stock[key] -1 # missing indent

#3

what is the difffrence between this and my own code?


#4

none, except i showed you which lines you need to think about indention (see comments)


#5

can you tell what is the correct code ?


#6

your code is correct, just check your indention, it needs a small improvement


#9

like this


#10

now the indention is better, but you use a double equal sign after stock[key], you should use a single equal sign to assign a new value, not a double for comparison


#11

A post was split to a new topic: Stocking out


#12