I cant understand evaluation method: | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
22nd Feb 2020, 3:06 PM
Prathvi
Prathvi - avatar
2 ответов
+ 2
it is tricky "1"+"2*2" is string concatenation so u have 12*2 as string😉
22nd Feb 2020, 3:26 PM
Oma Falk
Oma Falk - avatar
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
22nd Feb 2020, 3:11 PM
Utkarsh Sharma
Utkarsh Sharma - avatar