0

I would like to know it it is possible to convert a string made of numbers and symbols into actual numbers an symbols, for example '(12+23)*4' into (12+23)*4 script:

input = input('import calculation: ')

print(input)

Output ex:

3*5

Desired Output ex:

15

Thanks!

xtekky
  • 572
  • 1
  • 4
  • 13
  • This was already answered in https://stackoverflow.com/questions/2371436/evaluating-a-mathematical-expression-in-a-string – tomas Feb 18 '22 at 18:04
  • 1
    Do not use `eval`. Maurice has a good answer. Also see https://stackoverflow.com/questions/43836866/safely-evaluate-simple-string-equation – Matt Hall Feb 18 '22 at 18:04

1 Answers1

-2

you can use eval function directly, even if it's not recommended for security concerns.

eval(input('import calculation: '))

One more advice, do not name your variable as builtin function or imported ones, you're crrently doing monkey patching.

Félix Herbinet
  • 257
  • 1
  • 8