# ERROR IN - A Day at the Supermarket Making a Purchase

#1

IM GETTING THIS ERROR: Oops, try again. compute_bill(['apple']) resulted in a TypeError: unsupported operand type(s) for +: 'int' and 'str'

The code runs with no errors and the error message has no sense

``````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 key in food:
total = total + food[key]

print("TOTAL PRICES: " + str(compute_bill(prices)))
print("TOTAL STOCK: " + str(compute_bill(stock)))``````

#2

#3

This are the instructions:

Define a function computebill that takes one argument food as input._
In the function, create a variable total with an initial value of zero.
For each item in the food list, add the price of that item to total.
Finally, return the total.
Ignore whether or not the item you're billing for is in stock.

Note that your function should work for any food list.

Atually seems like the python compiler has an issue, even if I delete all the code and run the program it shows the same message: Oops, try again. compute_bill(['apple']) resulted in a TypeError: unsupported operand type(s) for +: 'int' and 'str'. This is the code I did for the excersice;

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 += food[item]

I am not calling the function and the same error displays :-/

#4

You misunderstood what I said. The part of the code I pointed out is wrong. The instructions say:

For that instruction set, you have:

The problem arises because you are using food as a list when you are suppose to be using prices(because you want the price of the food from the price list). So, it technically should be:

``total += prices[item]``

#5

Small typo, it should be:

``total += prices[item]``

Compute_bill(['apple']) resulted in a TypeError: 'dict' object is not callable
#6

Whoops! Sorry and thank you for catching that!

#7

I can't tell the difference.
In any case, I need help. Details at:

#8

Solved this issue has been.

#9

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 items in food:
total += prices[items]