How can i make the input accepts operations ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can i make the input accepts operations ?

ex : 3+5 == 5+3 ## If input is string the result will be wrong https://code.sololearn.com/cckNmfruQrHV/?ref=app

10th Jan 2018, 12:41 PM
Amine Trabelsi
Amine Trabelsi - avatar
4 Answers
+ 2
Use eval(); print (eval("3+5")) >>>8 print(eval("5+3")) >>>8 print(eval("3+5") == eval("5+3")) >>>True
10th Jan 2018, 1:02 PM
blackcat1111
blackcat1111 - avatar
+ 1
@blackcat1111 thank you
10th Jan 2018, 3:09 PM
Amine Trabelsi
Amine Trabelsi - avatar
+ 1
@Weronika it's already converted to float
10th Jan 2018, 3:11 PM
Amine Trabelsi
Amine Trabelsi - avatar
0
>>> a = "34.7" >>> float(a) 34.7
10th Jan 2018, 12:52 PM
Weronika Walczyk
Weronika Walczyk - avatar