Message from Python discussions
— What error?
/data/user/0/org.qpython.qpy/files/bin/qpython-android5.sh "/storage/emulated/0/qpython/integer.py" && exit
torage/emulated/0/qpython/integer.py" && exit <
please give you number.5.5
Traceback (most recent call last):
File "/storage/emulated/0/qpython/integer.py", line 3, in <module>
ValueError: invalid literal for int() with base 10: '5.5'
— 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
'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
— 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..
a is not a float, it remains being a string, because you read it from
— 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