Don't know what is the error


#1



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 numbers in food:
        total += numbers
    return total


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



#2

Hi @warsi3474,

You need to use your variable numbers to access the prices dictionary here ...

    total += numbers

See next post by @stetim94 .


#3

food (your function parameter) is a list of items you want to buy. so looping over food, numbers will contain product names (apple, banana and so on), you need to get from product to price, maybe you can use your prices dictionary somehow?


#4

still unsolved
please give specific code


#5

I got this
we have to return (total += prices[number])
instead of (total += numbers)


#6