Product "can't multiply sequence by non-int of type 'list'" error


#1



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


Oops, try again. Does your product function take exactly one argument (a list of numbers)? Your code threw a "can't multiply sequence by non-int of type 'list'" error.


Logically, I believed that my code would simply loop through the list and multiply the items but I obviously am in the wrong or else I wouldn't be here.


def product(array):
    
    total = 1
    
    for i in array:
        total *= array
    return total


#2

This is the line where the error is.

1 * [2, 4, 5, 7, 8]  =>  [2, 4, 5, 7, 8]

meaning total is now a sequence, not an integer.


#3

Wow I feel stupid. Thank you so much!


#4

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