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

8 Answers

+ 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.

+ 4

% is modulo or remainder operator. 1/2 = 0 with remainder=1.
so, 1%2==1

+ 1

integers only! đ
/---------\
2 / 1 \ 0
___/ \____
- 0
------------
1
------------

+ 1

HaRjit SiNgh yes yes yes, now it makes sense. give me another example please if you have one.

+ 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".

+ 1

HaRjit SiNgh thank you so much.

+ 1

anytime! Medo Hamdani đ€đ€

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 !