0

Why This ?

Why 10%20 equal 10?

30th Dec 2018, 10:35 PM
Edwing123
Edwing123 - avatar
20 Réponses
+ 6
If you try to divide 10 by 20, it is possible zero times. And you will keep a remainder of 10.
30th Dec 2018, 10:39 PM
HonFu
HonFu - avatar
+ 2
Probably it helps more if you understand what you calculate with modulo (the remainder). Have you understood it? Generally?
30th Dec 2018, 11:29 PM
HonFu
HonFu - avatar
+ 2
I understood when 2%2 = 0, 120%20 = 0, 13%2 = 1 but this one of the first number less than the second got me confused bro¡¡¡ i.e 2%12, 4%12¡!!
30th Dec 2018, 11:38 PM
Edwing123
Edwing123 - avatar
+ 2
You need to know, in x%y how many times y goes to x, then subtract it from x.
30th Dec 2018, 11:44 PM
Seb TheS
Seb TheS - avatar
+ 2
Seb TheS Omg god a shorter way lmao
30th Dec 2018, 11:48 PM
Edwing123
Edwing123 - avatar
+ 1
x%y = y*(float(x/y)-int(x/y)) 10%20 = 20*(float(10/20)-int(10/20)) = 20*(float(0.5)-int(0.5)) = 20*(0.5-0) =10
30th Dec 2018, 11:15 PM
Seb TheS
Seb TheS - avatar
+ 1
Okay, problem seems to be solved even if in a bit convoluted way. ;) Nightynight guys...
30th Dec 2018, 11:54 PM
HonFu
HonFu - avatar
0
Seb TheS, Is that the proper way to do it ... or are there other ways?
30th Dec 2018, 11:23 PM
Edwing123
Edwing123 - avatar
0
The Learner There are other ways, atleast I could have taken these int() and float() away, If I just would have known the language, that was used to be able to use floor division.
30th Dec 2018, 11:27 PM
Seb TheS
Seb TheS - avatar
0
btw, Thanks for answering my question guys 👍
30th Dec 2018, 11:44 PM
Edwing123
Edwing123 - avatar
0
I will offer the elementary school way of thinking (which I'm sort of using myself). 87%9 How often does the 9 fit whole into 87? Answer: 9 times. 9*9 is 81. And what will be left? 87-81=6. Now do the same with 10 and 20, or 2 and 12, or 4 and 12.
30th Dec 2018, 11:46 PM
HonFu
HonFu - avatar
0
Seb, not everybody understands when you write a lot of numbers and not a single word. (IF you understand, it is the most elegant way of course.)
30th Dec 2018, 11:48 PM
HonFu
HonFu - avatar
0
x%y = y*(float(x/y)-int(x/y)) cyberpunk2077 = x%y = x-int(x/y)
30th Dec 2018, 11:49 PM
Edwing123
Edwing123 - avatar
0
Oh, I see, we ended up writing the same. ^^
30th Dec 2018, 11:50 PM
HonFu
HonFu - avatar
0
x%y = y*(float(x/y)-int(x/y)) cyberpunk2077 = x%y = x-int(x/y)
30th Dec 2018, 11:50 PM
Edwing123
Edwing123 - avatar
0
cyberpunk... what? oO
30th Dec 2018, 11:51 PM
HonFu
HonFu - avatar
0
HonFu 10%20 = how often does 20 fit in 10? ans = 0 ? 0*20 ans = 0 ans = 10 - 0 ans = 10 ? omg
30th Dec 2018, 11:52 PM
Edwing123
Edwing123 - avatar
0
^^
30th Dec 2018, 11:52 PM
HonFu
HonFu - avatar
0
10%3 = 10-int(10/3)=7 10%3 = 3*(float(10/3)-int(10/3))=1 10%3 = 10-3*int(10/3)=1
30th Dec 2018, 11:53 PM
Seb TheS
Seb TheS - avatar
0
# Thank you man :) for i in "Thank you": print(i)
30th Dec 2018, 11:55 PM
Edwing123
Edwing123 - avatar