+ 1
What is quotient and remainder and how to use it
Not able to understood
2 Answers
+ 3
Quotient: A quotient is the result of performing a division. This is nothing that is related to python only, this is simply math.
This is the modulus operator. It does perform a division, but does not show the quotient but the remainder.
10 % 4 gives 2
10 / 4 gives 2. so 4 * 2 gives 8 and there is a remainder of 2 upto 10.
10 / 3 = 3 1
Dividend / Divisor = Quotient Remainder
+ 2
Quotient, floor division //, will perform a division, like true division /, but, floordivision will always evaluate to a whole number (exception: zerodivision).
In simpliest form floor division is just a division that results in a whole number:
1 // 10 = 0
7 // 2 = 3
99 / 10 = 9
10 / 3 = 3
Remainder, modulus %, will also perform a floor division, but it will only care what will be left by all succcessful floordivisions.
Remainder can be useful when you want to keep a number between 0 and any number, like in n % 10 result will always stay between 0 and 10, it might not be best way to do so, but it is easy and short:
1 % 10 = 1
2 % 10 = 2
3 % 10 = 3
9 % 10 = 9
10 % 10 = 0
11 % 10 = 1
0 % 10 = 0
-1 % 10 = 9