12/13 Plz help


#1

ana": 6,
"apple": 0,
"orange": 32,
"pear": 15}

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3}

def compute_bill(food):
total = 0
for item in food:
if stock[item] > 0:
total += prices[item]
stock[item]-=1
return total

Oops, try again.
calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 4 instead of the correct 7
Plz help I have tried so many times


#2

I missed out a bit of the top sorry about that


#3

Hi @facebook0 .

Glad you found the mistake.

Because the code that you posted is not formatted, it is difficult for other users to read and debug it. After code has been pasted into the editing window for posting, you can format it by selecting it, and then by clicking the </> button above the editing area. Alternatively, you can place three backquotes on the line before the code and three backquotes on the line after the code. This will enable us to see important details, such as the indentation and underscores. If you use the backquotes, your code will be color-coded, making it especially easy to read.


#4
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 += prices[key]
        stock[key] -= 1
    return total

I had to leave it alone after working on it for about an hour, but came back to it today and got it to work.


#5

same stuff happened with me! but still stuck with that..