Feed up, cant find what is wrong with my code.. plz help


#1



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


# Oops, try again. You shouldn't need to write out any of the food products. error message i got


#2

this line:

total = price[item] + total

you tried to access a item from your dictionary, but your dictionary is called priceS, not price (missing s at the end)(which should be lowercase, i just made it uppercase to show the difference)

It seems like the only thing wrong with your code, i ran it in 12. stocking out, is this the exercise you are at?


#3

thx.. but when I change it to (prices).. Im getting same error..

"Something of Value" i.e 10 exercise.. in ADay at the supermarket

shopping_list = ["banana", "orange", "apple"]
 
stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15,
}
   
price = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3,
} 
# Write your code below!
def compute_bill(food):
    total = 0
    for item in food:
        if stock[item] > 0:
            total = price[item] + total
            stock[item] = stock[item] - 1

    return total
print compute_bill(shopping_list)

#4

you shouldn't have renamed the dictionary, you should have done the exact opposite, make sure price in this line:

total = price[item] + total

matched prices by change price to prices


#5

I have done exactly what you have suggested to do, u can see my code

code used: same error

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

return total

print compute_bill(shopping_list)


#6

no you didn't, you still call the function:

print compute_bill(shopping_list)

and as the error message clear states, you shouldn't


#7

Hi getting same error..!! :frowning:

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

    return total

ERROR: Oops, try again.
You shouldn't need to write out any of the food products.

Tried all type of possibility getting same ERROR : Oops, try again.
You shouldn't need to write out any of the food products.

plz check help would much appreciated..


#8

code works fine, it should work. Maybe your browser is sending cached data after many attempts? Try a different browser


#9

I have tried all possible things like clearing cache, using in different browser, different computer, same error, please let me know wht to do.. :frowning:


#10

Okay, i am out of idea's, i will ask around


#11

uhm... the code you have is for exercise 12. stocking out, you are only at exercise 9. something of value, which doesn't add up


#12

Its really my bad.. I really want to thank you for your help.. got it..!!! :wink: