Making purchases


#1




Oops, try again. Your code looks a bit off. Check the Hint if you need help! Your code threw the following error: name 'food' is not defined

Traceback (most recent call last):
File "python", line 31, in
NameError: name 'food' is not defined


Replace this line with your code. 
shopping_list = ["banana", "orange", "apple"]
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}

shopping_list = ["banana", "orange", "apple"]
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}

def compute_bill(prices):
    total=0
for item in food:
    total=food[item]+total
    print total


#2

The above is repeated. Remove one of them.

This is where food should be defined in the parameter.

def compute_bill(food):

food is not a dictionary. Here is where we would use prices, the dictionary we doing price lookups in.

This looks like it is inside the loop block. There is indentation required on the for loop since it is inside the function block.

def ___(food):
    total = 0
    for ___:
        total = total + prices[item]
    return total

print compute_bill(shopping_list)

#3

Oops, try again. You shouldn't need to write out any of the food products.
error ^
Code:

shopping_list = ["banana", "orange", "apple"]
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}

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

#5

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