11/13


#1

I used the following code (located at the bottom of the question) and it worked. That said, I'm confused:

Would someone please explain it line-by-line? The specific question that I don't understand is, "why are we creating an argument 'food' that correlates to a list called 'food' when the list doesn't exist and we're only scrolling through 'prices' to source our answer?" There's probably a simple answer, but it's escaping me right now...

Any help would be appreciated.

def compute_bill(food):
total = 0
for x in food:
total += prices[x]
return total


#2

the list 'food' is being generated by codeacadamy in the background so you don't see it.
If you could see it, it would look something like this:
lst = ['apple', 'orange', 'banana']
score = compute_bill(lst)
this passes everything in the lst variable to the compute_bill function your creating and gives codeacademy your final output to see if you got it right.

Breaking the code you created line by line.

# First you define a function called 'compute_bill' that with an argument called "food"
def compute_bill(food):
    # then you create a variable called 'total' to keep track of the total cost and set it to 0
    total = 0
    # now you run a for loop on each item in the 'food' argument your function compute_bill got from codecadamy
    for x in food:
        # tell total to add the value of item from food its dealing with to its self.
        total += prices[x]
    # now close everything and return the final total after the for loop has completed
    return total

I hope this helps