Wats wrong?


#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 prices['banana','orange','apple'] in food:
total +=prices['banana','orange','apple']
return total


Replace this line with your code.


#2

you can do the loop just by calling any element (I call them "e") in food, the format of your loop should look more like:
for e in food:
the indentations are VERY important here. if you set return with indententaion after the loop, your loop will stop after the first round, make sure your return is set for the function
I personally called the function afterwards by using print cmpute_bill(shopping_list), that way I get the result printed in the console.
Remember also that you want to calculate how much you are paying from your shopping list, not a summ of all the elements available in prices.
I don't want to write the answer because it kind of defeats the challenge :slight_smile:
hope it was useful


#3

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