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

14th Apr 2018, 11:19 AM
Maninder $ingh
Maninder $ingh - avatar
2 ответов
+ 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
14th Apr 2018, 11:24 AM
Burey
Burey - avatar
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.
15th Apr 2018, 1:44 PM
Half Byte
Half Byte - avatar