Finding the product of a list of numbers

I’m trying to find the product of a list of numbers.

That’s all!

Thanks in advance.

What have you tried so far? Please show some effort.

Just trying out some python which I don’t really understand, neither loops in Dynamo code.

I don’t see the point in sharing non-functioning Dynamo graphs or python scripts.

Hope this helps :slight_smile:


Note : A funny way to do it would be to compute the log() of every item, sum this logs, then apply exp() to the sum :stuck_out_tongue:

Note : The python way to do it :slight_smile:

liste = IN[0]
result = 1
for i in liste:
	result = result * i
OUT =  result
1 Like

The point is to show the work you’ve done so far so that a) we can help explain why something might not be working and b) so we’re not just doing your work for you.

Works as it should.
Thanks a lot!
I should really learn how to use loops in the Dynamo scripts…

I highly recommend avoiding loops in Dynamo outside Python :slight_smile:

Edit : The only case that oblige you to work with loops in Design Script is when you have a result that depend on the value of every item of your list (which is the cas here) AND when you have to use a Custom Node (or at least a function not callable in Python) (which is not the case here)

I agree with @mellouze. Dynamo doesn’t really support “loops” in the way that most people are familiar with. It’s best not to think in terms of looping through data in the Dynamo environment. Python, however, is great for loops.

I understand the annoyance with someone just putting out an “make this for me” but please don’t confuse the simplicity of my original comment with laziness. This is a very “singular” step to take so there’s not much to show that can be improved.

Annoyingly I just haven’t really managed to wrap my head around how to handle loops (aside from using while loops in C several years ago).

So while typing this I saw you and @mellouze comment that creating a loop in Dynamo is a bit of a pain so I guess I’ll invest time in learning it in Python in which case I’m still having trouble actually getting the result of the loop out of the Python node (at least, I think that’s the problem).

I know you’re not just asking for us to do it for you. You know better than that. :grin:
I was more concerned with seeing whether you were trying python or design script and what kind of looping you were attempting. It was a very “basic” question so I was just trying to discern what your specific issue was.

And for what it’s worth, I prefer python over design script for anything involving loops. A simple loop like this is basically the same in either syntax but (I think) the formatting is way easier in python.

dataEnteringNode = IN
nums = IN[0]
product = 1

for num in nums:
	product = product * num

OUT = product
1 Like

That looks easy enough.