I get the following error message: "Oops, try again. Your function fails on product([4, 5, 5]). It returns 20 when it should return 100."

I don't quite know what i'm doing wrong.

def product(lst):
    lst_int = int()
    index = len(lst)
    for x in lst:
        index -= 1
        lst_int = x * lst[index]
    return lst_int
print product([1,2,3])
print 1 * 2 * 3


You are overthinking this, try following this template:

    VARIABLE = 1
    return VARIABLE


Thank you very much! However, that very much resembles the original design of my function, with the only difference (as far as i remember) being that my VARIABLE = 0, which returned an error code as well.

If there any difference in having a variable = 0, and a variable = 1 in terms of the behaviour of the function?


Yes, there is in fact a difference. Computers, unlike you and I, start counting at 0. So, in order for us to insure that a mathematical equation works, we must set our starting point at 1. This way the computer and program will know to start counting from 1.


Okay. Thank you very much for your help!


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