Why doesn't work checking of this exercise?


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

print compute_bill(shopping_list)

this is my code, but it doesn't work


#2

Then you'll need to compare what it does to what it should be doing. The term "work" is a way of avoiding that and is something you should avoid. Once you've done that comparison you can start considering which part of your code might be responsible for that behaviour, or perhaps convince yourself of what steps the code should be performing in order to not have that behaviour.

And also, if you're going to share code, then you will need to ensure that the code is intact when others view it, otherwise they are looking at something other than your code which defeats the purpose of sharing it.


#3

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