TypeError: 'function' object is not subscriptable

I’m having a problem with my code it give me this message and I can’t seem to find my mistake.Could someone help me please .

def produit(x):
    somme = 0
    for i in x:
        somme += x(i)
    return somme
tab = []
for i in range(4):
    prix = int(input("enter price"))
somme = produit[tab]
1 Like

Hi @gustyna,

You have this line:

somme = produit[tab]

With the square brackets, the statement attempts to subscript the produit function, when instead, it should use parentheses to pass tab to that function as an argument.

The produit function contains this:

        somme += x(i)

It attempts to call x as if it were a function. Instead, x would actually represent a list. Based on the for loop header, i would then represent an item within x during each iteration, and should be added directly to somme.

Edited on February 27, 2019 to address several issues within the user’s code