0

Is there any way to use a numeric operator from a list in a sum. For example, if I had a list called BASICOPS, which consisted of ['+'], could I then use it in a sum, which is for example:

(1,(BASICOPS),2)

to make the sum 1+2? I am trying to do this to make a game where the operator for a question is random. So in the game the list would have mulitple operators, and these would be selected randomly using their index, which would be randomly selected.

Paul Rooney
  • 20,879
  • 9
  • 40
  • 61
  • `eval(''.join(['1', '+', '2']))` returns 3, but I think you'll need to make some modifications for what you want. – OneCricketeer Nov 29 '15 at 23:38
  • i'm shooting around in the dark, i'm new to python. so far i attempted to name the variable + 'ADD', with there being apostrophes around the +. – hjammins Nov 29 '15 at 23:53

0 Answers0