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


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


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.


Wow I feel stupid. Thank you so much!


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