13/15 Whats wrong with my code


#1

def product(numbers): # mine, wrong
lst = []
total = 1
for ele in numbers:
total *= ele
lst.append(total)
return total

print product([4,5,4])


#2

First off, you could make the function a lot smaller if you just get rid of the lst list. Second, you are multiplying total by a string, not an integer. What you have to do is total *= int(ele).

The function I wrote for this was:

def product(numbers):
total = 1
for elein numbers:
total*=int(ele)
return total

That is the function that I got, and I’m pretty sure it will work for codecademy.


#3

Thank you, that looks like what I attempted. Im getting a bit confused when I need to add the blank list in my function.


#4

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