0
This code- (8+4)/2 displays6.0 but not 6.why?
3 Answers
+ 12
Division on integers creates a float result, you can convert (or cast) the result into integer for getting the desired output.
int((8+4)/2)
+ 9
I am not getting 6.0 when I do (8+4)/2, but it may be that the division operation is returning a float in your case.
So, to return integers, use floor division (//) or cast the return type to int.
Eg :
>>> (8+4)//2
6
>>> int((8+4)/2)
6
+ 8
(8+4)2 gives me 6 here not 6.0,not sure what your case, but use int() to convert and to integer