13. product


#1



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


Oops, try again. Your function fails on product([1, 2]). It returns 0 when it should return 2.


The code looks fine.


def product(lst):
    lst = [int()]
    total = 1
    for num in lst:
        total *= num
    return total


#2

could you explain your thought process about this line:

lst = [int()]

`


#3

I thought this would mean a list containing integers, as I put 'int' inside the square brackets. Does it mean something else?


#4

Sorry, what is wrong with this line?


#5

I understand it, I have taken that line out. Now it works!

def product(lst):
    total = 1
    for num in lst:
        total *= num
    return total

#6

Well, for starters, It's unnecessary. My suggestion to you, is to read more into parameters. I'm positive doing this will help you to not make errors such as this in the future.


#7

Ok thanks!:slight_smile:


#8

do you also understand now?


#10

I'm going to take that as a yes.


#11

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