12/10 Stocking Out


#1



Exercise here

For the following code, I got this error message:

Oops, try again.
calling compute_bill with a list containing 1 apple, 3 pears, 1
orange and 9 bananas resulted in 46.5 instead of the correct 34.5


I know I'm doing something wrong, but I'm not sure what.


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


#2

instead of this, try and increment total by prices[items]

also you need to decrement your stock before you return total

also, also, you need to delete your print statement at the end of your code!


#3

Thank you! :slight_smile: I love your icon, BTW.


#4

No problem, glad I could help.

& thanks :stuck_out_tongue:


#5

@nickgrimes50, How would you write the decrement into the code??


#6

@paisocrazo you use -= to decrement in python