12/13 Right For the Wrong Reasons


#1

I took a break and I am having issues knowing the call mechanics. I changed stock[item] to stock[n] and I have no idea why the code suddenly started to work.

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 n in food:
if stock[n] > 0:
total += prices[n]
stock[n]-= 1
return total


#2

When you use

for n in food

n is the variable that will take on all the different values in the food list. If you write

for n in some_list:
   print item

it won't work, but both

for item in some_list:
    print item

and

for n in some_list:
    print n

are fine.