Message from Python discussions

December 2018

— What error?


/data/user/0/org.qpython.qpy/files/bin/ "/storage/emulated/0/qpython/" && exit
torage/emulated/0/qpython/" && exit <
please give you number.5.5
Traceback (most recent call last):
File "/storage/emulated/0/qpython/", line 3, in <module>
ValueError: invalid literal for int() with base 10: '5.5'
1|hwedison:/ $

— Like this

— That's because it's a float

— Not an integer

— Sorry. i will try to behave good.pls forgive my beginner sillyness.

— Easy, it's a bot just telling you to use `

— That's because your input is a string, '5.5' in the first example when you do: b = float(a) b becomes a float number, next when you do c = int(b), c becomes the integer part of b, that is 5, in the second case, a is still a string '5.5' and when you do c = int(a) it throws the error

Message permanent page

— But i think a is always a str. b=float(a) b is a float

— And even if a is a float.the codes are still should be logically right. but computer tells me wrong which drive me crazy..

Message permanent page

— a is not a float, it remains being a string, because you read it from input

— You can't cast from string to integer if the string is not correctly formatted (and you can't assure it will), but you can cast from float to integer because Python knows how to handle numbers

Message permanent page