I have an error and dont know were it is,


hello my name is rafael,
i am having truble in the part of Making a Purchase i grown averything as the istruccion told me to but i dont understand the error tat the program is marking it said that "Oops, try again.
compute_bill(['apple']) resulted in a TypeError: unsupported operand type(s) for +=: 'int' and 'str'"
my code goose like this
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):
for thing in food:
total += thing
return total
i will thank the hellp frome anyone. thank for your time


Hi @javaplayer72651,

The part that is problematic is here:

According to the instructions, you are supposed to:

03. For each item in the food list, add the price of that item to total.

Consider that when you call your function, compute_bill, the argument passed is likely to be something like shopping_list. Does it make sense to add the items in shopping_list (e.g. "banana") to total? This is what the error is pointing to: that you are adding a string like "banana" to an integer (i.e. 0, which is represented by the variable total).

To improve things, think carefully about what the instructions require you to do. You are supposed to add the price of the item to the total, and not the item itself to the total.

And how can you do this? Hint: Recall how to access keys in a dictionary, particularly a dictionary such as prices.

Good luck! :slight_smile:


hey that true thanx a very much,
i didt tought taht "shopping_list" was a valid argument , but now i notice taht if you wanna to call on a list you can takeit as an agumen , agin thanks a lot!!!