12 - Stocking Out


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(shopping_list):
total = 0

for food in shopping_list:
if stock[food] > 0:
total += prices[food]
return total

What’s wrong with my code?


Ensure that your code is intact if you want others to read it

And if we’re to know where to look/what to look for, then you’ll need to explain how it acts differently from what you want. This is also the first step to solving it yourself - identifying the problem - and you may find yourself solving it on your own while formulating your question


You didn’t include code to reduce the stock.