+ 1
I cant understand evaluation method:
2 Answers
+ 2
it is tricky
"1"+"2*2"
is string concatenation
so u have 12*2 as stringđ
0
If you only want answer to the problem, you can write same code in the code playground.
eval() performs operations on the strings as if they are integers, inly if the strings are like-
"2*3" or "4*8" or "7+8" etc.
For example --
eval("7*2+1") will give 15
it performed the mathematical operations given in string.
But if you simply do print("7*2+1") it will print the string as it is i.e, 7*2+1
but it gives error if something in the string cannot be evaluated such as "7+cb*2" only if the cb is not defined.
if you define cb, it has to be int, not string.
For Example--
b = 1
c = eval("7*b +1")
print(c)
It will show 8 but
b = "1"
c = eval("7*b +8")
will give error.
you can refer to this similar question.
https://www.sololearn.com/Discuss/428351/?ref=app