Can any help me to understand the logic behind this code works?

a=0
for j in range(1, 10000, 7):
    a = a+j
print(a)

Hi @narasimhan94,

In the above snippet you’ve:

  1. Initialized a as 0.

  2. Opened a FOR loop with every j in the range [1, 10000] (10000 excluded) with a step size of ‘7’, i.e. j = 1, 8, 15, 22, 29, ... etc.

  3. At each step, you’ve performed a = a + j

  4. Finally, outside the FOR block the value of a is printed

1 Like

thank you very much @Bilal_Aamer

it’s clear now

1 Like