View Full Version : [HELP] Multiplying a series of added values

 SirMatthias11 November 2012, 01:30 PMHello all, hopefully this makes sense...as I'm still trying to figure out how to best word it. I'm working on a script where I want to add/remove values to a list using check boxes. The problem I'm having is I want some of these values to multiply with each other, before producing a final result, and I'm not sure how to do that (especially if the number of values changes)...and I also don't know what the proper mathematical term for that is...if there is one. Can anyone point me in the right direction?
ldunham1
11 November 2012, 01:51 PM
could you give an example?
ideally a list with some values and what you want multiplied with what, as there could be many ways in which you mean.

ie [1, 2, 3, 4]
1x2, 3x4
1x2, 2x3, 3x4
((1x2)x3)x4
and so on...

SirMatthias
11 November 2012, 01:56 PM
Thanks for the quick response!

as in (input1*input2*input3*input4...)

and if I want to take out input3, have the calculation obviously be (input1*input2*input4).

Does that help?

SirMatthias
11 November 2012, 02:58 PM
This is the idea i'm going for. No need to read beyond the intro paragraphs.

http://en.wikipedia.org/wiki/Empty_product

ldunham1
11 November 2012, 08:58 PM
not a problem, im sure theres a function within the math module, I cant think of what its called. In the meantime however this seems to do the trick.

numlist = [ 1, 2, 3, 4, 5 ]
#set initial value
result = numlist[0]
# loop through the rest of the list
for i in range( 1, len( numlist ) ):
#multiply the result by the next item
result *= numlist[i]
print result

SirMatthias
11 November 2012, 11:25 PM
You are awesome!

Thanks!!! :beer:

ldunham1
11 November 2012, 08:13 AM
not a problem.

CGTalk Moderation
11 November 2012, 08:13 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.

1