0

1/3 gives zero on my python

28th Dec 2016, 9:17 PM
Richmond Wejoye
Richmond Wejoye - avatar
4 Respuestas
+ 4
Print (float(1/3)) gives you your answer of 0.333 recurring You need to make the answer a float. Integers divided by integers always result in integers
28th Dec 2016, 9:51 PM
Paul Bartholomew
+ 2
its integer type, so it will give you zero if the result was decimal
28th Dec 2016, 9:32 PM
Muhammad Sultoni
Muhammad Sultoni - avatar
+ 1
no, float(1/3) will not give 0.333 it will give output 0.0... float (1)/3 will give 0.333, in the above case float statement is converting 1/3 to float while in second case it is converting 1 to float then division occurs.. 1/3 is int type that's why it will give output as 0..
29th Dec 2016, 5:48 PM
Himanshu Vishwakarma
+ 1
You are using Python 2, unfortunately for you...
30th Dec 2016, 6:02 AM
Amaras A
Amaras A - avatar