+ 10
Why 0 is execute?
x=10 for i in range(1,11): x%=i print(x) #ouput=0 0 0 0 0 0 0 0 0 0 but why can anyone explain me.
2 Answers
+ 14
in the first iteration, x is assigned the value of 10 % 1:
x = x % i
x = 10 % 1
x = 0 (any number % 1 is 0)
from this point on in each iteration, the value of x is 0
and 0 % number is always 0
0
In the first iteration:
x = 10 % 1, so x becomes 0
Thereafter, for i from 2 to 10, x % i evals to 0 % i, wich is always 0, for any value of i.