+ 2

Please explain this code answer? print (-11//3) print (11//3) outputs are -4 3

I see this is on many numbes . I think output will be -3 3. That is incorrect why?? https://code.sololearn.com/cRtHvBxHS9mP/?ref=app

11th Oct 2020, 2:15 AM
Sâùtôsh
Sâùtôsh - avatar
1 Answer
+ 5
11 does not evenly divide by 3. // always rounds down. Put those facts together and you should see why -11 // 3 is -4 while 11 // 3 is 3. The JavaScript equivalent is like Math.floor(-11 / 3) which is -4 and Math.floor(11 / 3) which is 3.
11th Oct 2020, 2:29 AM
Josh Greig
Josh Greig - avatar