0
Quotients
I’m not too sure what is print(10//4) I know that was the exercise but I really do not understand how it is 2? 10/4 two times ? And not too sure about the % as well when there’s a print(7%5//2)
8 Respostas
+ 7
Farnaz.A ,
saying "... Just rounds the number..." can be misunderstood, because round can be done up or down.
the definition is like:
▪︎the floor of a real number is the largest whole number that is less than or equal to the number.
in a more simple way: the number is rounded down
+ 4
print(10//4)
called floor division, returns integer value
10/4 is 2.5, it takes just the integer and discards the floating points.
print(10/4)
called normal division, returns exact floating point value.
print(7%5//2)
% returns the remainder of a division
7%5=2 then 2//2=1
+ 2
I see ! Thanks guys !
+ 1
Avinesh "floor division" is called "floor" because it doesn't "just discards the floating points" as int() do (truncate number)
print(-5//2) # -3
print(floor(-5/2)) # -3
print(int(-5/2) # -2
0
// give whole duvision result
% give whole duvision remainder
so:
V == ( ( V // D ) * V ) + ( V % D )
== ( N * V ) + R
with N and R integers
in more human language:
V // D return interge N times D fiting in V
V % D return integer R count of rest after removing N times D from V, so 0 <= R < D
0
Thanks visph I pretty much meant the same, probably didn't frame it well.