4 Respuestas
+ 6
s=input()
print(eval(s))
+ 1
Using eval for that case is not secure, see the documentation for eval. It is possible to inject "bad" commands.
I think the right ways is to use a parser (there are lots of packages available and you do not reinvent the wheel).
Over simplified you can use the following code to calculate simple additions and multiplications of integers like 1+2*3:
from math import prod
s=input()
print(sum(map(lambda m: prod(map(int, m.split("*"))), s.split("+"))))
With a parser you have to specify a grammer which determin the expresion which could be parsed and considered as valid.
I hope that helps.
0
str=input()
b="print("+str+")"
exec(b)
https://code.sololearn.com/cYdRBd0061I8/?ref=app