Product stuck


Your function fails on product([1, 2]). It returns 5 when it should return 2.

i don't know how to multiply 2 by 1 , instead of multiply 2 by itself and add to it result of 1 multiplyed by itself , sorry for my english

def product(numbers):
    lst = 0
    for i in numbers:
        if i != 0:
    return lst


First, you lst needs to be 1 when it's initialized. That way you can lst *= for each item in the given list. You don't need the if statement, because if there is a 0 in the list, then you want to multiply it even though it will end up being 0. You don't need to add i to lst.

def product(numbers):
    lst = 1
    for i in numbers:
        lst *= i
    return lst


Thanks , man :slight_smile: It works


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