+ 2

Why output is False?

a=9**19==(int(float(9**19))) print(int(a)) #output = 0 but why can anyone explain it.

18th Aug 2018, 4:40 PM
Maninder $ingh
Maninder $ingh - avatar
6 Réponses
+ 7
Apparently some digits are being truncated when you do int(float()) casting. Run in a Python shell to see the difference.
18th Aug 2018, 4:54 PM
Eduardo Petry
Eduardo Petry - avatar
+ 4
You can't assign value to variable and compare it at once. What do you think what 'a' is? 9**19 or boolean
19th Aug 2018, 8:17 AM
Roneel
Roneel - avatar
+ 2
I believe it has to do with the float function and how floats are handled in Python. https://docs.python.org/2/tutorial/floatingpoint.html
18th Aug 2018, 4:52 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 2
try this a=9**19 print(int(a)) b=int((float(9**19))) print(b) You will see the difference
18th Aug 2018, 5:54 PM
E_E Mopho
E_E Mopho - avatar
+ 1
a=int(9**19) print(a) #outputs 1350851717672992089 a=int(float(9**19)) print(a) #outputs 1350851717672992000 It seems that either "float" or "int" has some issues with python.
19th Aug 2018, 7:36 AM
SomeOne
0
Just because of different estimations by compiler.
19th Aug 2018, 8:17 AM
Tanveer Raza
Tanveer Raza - avatar