Making a Purchase confusion


#1

My code returns the error
"Oops, try again. compute_bill(['apple']) returned 10.5 instead of 2"
the code works but it is not what the question is demanding, any help would be greatly appreciated!

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 x in prices:
total += prices[x]
return total
print compute_bill(shopping_list)


#2

why are you looping over prices?

you should loop over food, this way, you can call the compute_bill function with different shopping lists (this represent different customers)


#3

you are an absolute star!


#4

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