So, I've seen all the correct code for this exercise, so I know what to write.
I've also looked at this video on youtube
But I cannot advance unless I understand the logic behind it, wich I don't. Here is what I can't understand:
We have to define a function that will automatically compute our bill. As a customer?
Obviously our total starts at zero
total = 0
From what I understand, as a customer I buy the three items listed at the top. (see image)
So i'm buying one banana, one orange and one apple. Right??
- Here is where I get lost.
for i in food:
How does the code knows what food I need. There's no reference to shopping_list???
- How come the result stays the same, when i change "i" to "item" or to any other word. I don't understand.
As you can see, I'm super newb, be gentle.
def compute_bill(food): total = 0 for i in food: if i in stock[i] > 0: total += prices[i] stock = stock[i] -1 return total