Product


#1



13. Product


Help please


def product(numbers):
    numbers = str(numbers)
    total = 0
    for x in numbers:
        total *= int(x)
    return total

Error message: Your code looks a bit off--it threw a "invalid literal for int() with base 10: '['" error.


#2

Hi, @joaquimbarreto,

There are several issues to address here.

The first problem to consider concerns this line ...

    numbers = str(numbers)

What is the purpose of converting numbers from a list to a str object?


#3

To make them integers. I'm not sure.


#4

maybe this:

def product(numbers):
numbers = []
total = 0
for x in numbers:
total *= int(x)
return total
??


#5

An example of a call to the product function is ...

print product([6,8,12,2])

With that call, numbers will already be a list of ints. No conversion is necessary.

You should not do this either ...

numbers = []

That assigns an empty list to numbers.

Iterate through numbers as it is.

Is this correct? ...

total = 0

What is the result of multiplying any number by 0?


#6

zero

ok I got it. many thanks!!!


#7

Very helpful. thanks. I can move on.


#8