0

Very simple. %

x = 1 % 2 print(x) #How come the output is 1? I am aware if the rule. But the normal division of 1/2 = 0.5 and 00 as the output. Thanks

18th Apr 2018, 1:40 AM
Medo Hamdani
Medo Hamdani - avatar
8 Respostas
+ 1
1/2=1 If you're using ints, system won't use floats even in quotient part. So system doesn't know what the heck is decimal (.) Therefore, nmbr smaller or equal to 1 which is divisible by 2 is 0, so 2*0=0, 1-0=1. Hence, remainder is 1.
18th Apr 2018, 3:08 AM
Harjeet Singh
Harjeet Singh - avatar
+ 4
% is modulo or remainder operator. 1/2 = 0 with remainder=1. so, 1%2==1
18th Apr 2018, 1:51 AM
J.G.
J.G. - avatar
+ 1
integers only! 👇 /---------\ 2 / 1 \ 0 ___/ \____ - 0 ------------ 1 ------------
18th Apr 2018, 3:12 AM
Harjeet Singh
Harjeet Singh - avatar
+ 1
HaRjit SiNgh yes yes yes, now it makes sense. give me another example please if you have one.
18th Apr 2018, 3:16 AM
Medo Hamdani
Medo Hamdani - avatar
+ 1
Umm no i don't have any other examples to explain!🤐 But you can check with, 2/3=2, 10/6=4. As the questions says, it is "very simple".
18th Apr 2018, 3:20 AM
Harjeet Singh
Harjeet Singh - avatar
+ 1
HaRjit SiNgh thank you so much.
18th Apr 2018, 3:25 AM
Medo Hamdani
Medo Hamdani - avatar
+ 1
anytime! Medo Hamdani 🤜🤛
18th Apr 2018, 3:26 AM
Harjeet Singh
Harjeet Singh - avatar
0
J.G. 1/2= 0.5 , so it will be 10/2 I know the rule. like 2%2=0 but 1%2 = 1 !
18th Apr 2018, 2:12 AM
Medo Hamdani
Medo Hamdani - avatar