+ 1

Floor division and modulo operator?

Can i ask? what is floor division("//") and modulo operator ("%")? I still don't get it. In my school there is no lesson with it, so can anyone explain it to me. Thank you in advance!

13th Aug 2018, 10:28 AM
NicoTexT
NicoTexT - avatar
5 Answers
+ 3
This doesn't tell the whole story, but maybe it's a good starting point (as long as numbers don't get negative): Q: How often does the 6 fit into the 20? A: 3 times! // Q: But what will be left after that? A: 2! %
13th Aug 2018, 11:22 AM
HonFu
HonFu - avatar
+ 1
Modulo operator gaves you the remainder of the division of those numbers: Ex 5 / 3 returns 2, as 5 over 3 is 1 with a remainder of 2. Floor division gaves you a integrer result, no matter the result is a float or the numbers used are float or not. EX: 5/2 -> 2.5 5//2 -> 2
13th Aug 2018, 10:36 AM
Fabian
+ 1
Making a division m/n it's just like making"packs" of n elements of a total of m elements. Imagine you have 10 apples, and you want yo make packs of 3 apples. How many packs can you make? 3 full packs. However, there is one apple left, and you can not make a full pack with just one apple. The modulo is the number of items left, which are not enough to make a full pack. In this case, as we have one apple left, we have a modulo of 1 10 / 3 gaves you a remainder (modulo) of 1. Written in Python, a = 10%3. In this case, the variable a holds the value 1.
13th Aug 2018, 10:49 AM
Fabian
0
I still don't get it? the mudolo operator
13th Aug 2018, 10:41 AM
NicoTexT
NicoTexT - avatar
0
so, in floor the division it is just like a division but it always gives you an integer answer? so my i ask why is 20//6 = 3? right?
13th Aug 2018, 10:43 AM
NicoTexT
NicoTexT - avatar