+1

Print (-11//3)

How can to get output (-4)

10/3/2019 7:20:49 PM

roza alandalib

12 Answers

New Answer

+2

Maybe the actual result is -3.5x so python will automatically round up

+2

Actually in python there are two division rules * Ordinary division, with / operator * Floor division, with // operator Here are some explanation to your questions.... These are for perfect division, means which does not give value in decimal >>> 10/2 5 >>>10//2 5 But, for not perfect division >>>10/3 Mathematical result is 3.33333 3 3<3.33333<4 >>>10//3 Mathematical result is 3.33333 3 3<3.3333<4 From above example for not perfect division u can see that floor division means after performing the division, results in the lower integer to the value Therefore, >>> -11//3 -4 -4 < -3.66666 < -3 , from above floor definition it is clear that after division it results in the lower integer to the value that is -4

+2

I understood this point clearly

+2

+1

You mean that "//" is round up ok Thanks so much

+1

No, // is floor division

+1

Ok...floored quotient

+1

Mirielle Seb TheS Don't confuse the floor function with the trunc function. By definition, floor(x) returns the largest integer less than or equal to x. In other words, floor(x) rounds down to negative infinity. roza alandalib Please use the search bar before posting to avoid duplicates. https://www.sololearn.com/discuss/461705/?ref=app

+1

Thanks for every one

+1

Diego so what should i call this "//" and check my first comment

+1

Your welcome 🤟

0

I think modulo has something to do with that weird behaviour, where negative floor divisions get decreased by 1. If you think floor division as: X % Y = X - Y * (X // Y) There would be cases, where there would be negative results, which is not wanted from modulo: #Here -10 // 3 = -3 -10 % 3 = -10 - 3 * (-10 // 3) = -10 - 3 * (-3) = -10 + 9 = -1 If we always decrease to lower whole number in case there are decimal places, it wouldn't happen: #Here -10 // 3 = -4 -10 % 3 = -10 - 3 * (-10 // 3) =-10 - 3 * (-4) = -10 + 12 = 2 It is just a theory. I think it is annoying, because I think it floor division would just ignore the decimals, but this modulo theory explains well.