- 4
Python
When we operate (4+8)/2 we get 6 only.....but you are given the output as 6.0
5 Answers
+ 11
Python display numbers by visual explicit format difference between floating point and integer number by appending '.0' to an integer value internally stored as a float one: in Python 3 slash ('/') is the operator for float division and always return a float value, while ('//') is integer division and return an integer... and int() cast the argument to integer value (stored as integer)
+ 9
(4+8)/2 gives 6.0
(4+8)//2 gives 6
(5+8)/2 gives 6.5
(5+8)//2 gives 6
// is used to get quotient only
/ is used to divide number without leaving any remainder i.e. the value will be in decimal. So, it gives 6.0 instead 6
+ 8
/ is just normal division, the return value is a float.
To get rid of decimal places, use int() or //.
Both works the same way
+ 7
Try int((4+8)/2)
+ 5
@Kartikey, in the last example, it seems you mistyped // with /, the one that gives quotation 6, please fix that so not to confuse the TS. Thanks :)