Why print ( int("2.5") + int("3.5") ) error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why print ( int("2.5") + int("3.5") ) error?

1st May 2018, 3:34 PM
ramesh sarkar
ramesh sarkar - avatar
5 Answers
+ 3
Its because you can't convert "2.5" to an integer, here its trying to get an integer with value of 2.5 thats not possible. Use float instead
1st May 2018, 3:55 PM
Koushik Naskar
Koushik Naskar - avatar
+ 3
Yep. You can convert an integer that is a String to float: float("3") = 3.0 But you cannot convert a float that is a String to an integer: int("2.5") : illegal. Will throw an exception Here is a tutorial about type conversion. Might be helpful. https://www.datacamp.com/community/tutorials/JUMP_LINK__&&__python__&&__JUMP_LINK-data-type-conversion
1st May 2018, 4:03 PM
cyk
cyk - avatar
+ 1
thank you Soo much 😊
1st May 2018, 4:04 PM
ramesh sarkar
ramesh sarkar - avatar
0
what language
1st May 2018, 3:36 PM
NIkola Radunovic
NIkola Radunovic - avatar
1st May 2018, 3:36 PM
ramesh sarkar
ramesh sarkar - avatar