How to Iterate through arithmetic operators across a static, excecutable formula in Python?

Viewed 1202

I'm trying to use itertools to iterate through mathematical operators. Typically with an array of [1, 2, 3], using combinations I can get the results:

1
1,2
1,3
2,3
1,2,3

etc.

I want to use this on an array of [1, 2, 3] in such a way that:

1+2+3
1+2-3
1+2/3
1+2*3
1-2+3
1-2-3
1-2/3
1-2*3
...

arises and gives results of the equation.

How might I go about doing this?

4 Answers
Related