13. Product: Code seems to work. Not being accepted


#1



https://codecademy.com/courses/python-intermediate-en-rCQKw/2/3?curriculum_id=4f89dab3d788890003000096#


I've run multiple tests and always get the correct answer. Not sure what this error message means, as I don't see any division by zero occurring. Insights appreciated!


def product(seq):
    total = seq[0]
    for x in seq:
        total *= x
    total = total/seq[0]
    print total
    return total


#2

Never mind. I got it to work by using the simpler:

def product(seq):
total = 1
for x in seq:
total *= x
print total
return total

Still not sure what that error message was all about though...


#3

Here you should set total to 1, then you can deletete the total = total/seq[0] part. Otherwise your function wont work if the first element of seq is a 0. Note that multiplication by 1 doesn't change a number.

Also you are trying to use product(test) before defining what test is.


#4

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