49.9k views
0 votes
J = 0

for i in range(1, 10, 2) :
if j < 10 :
j = j + i
print(j)

What does that 2 do?

2 Answers

3 votes

Answer:

The 2 in the range() function serves as the step size, meaning it determines how much the value of i increases by each iteration of the for loop. In this case, the value of i will increase by 2 each iteration, starting from 1 and going up to 9. So the for loop will only run 5 times, with the values of i being 1, 3, 5, 7, and 9. This is why the final value of j is 25.

User Tomas Brambora
by
4.9k points
2 votes

Answer:

it jumbs by 2

lets me give you a example J=0 next step goes by 2 which means J=

Step-by-step explanation:

User Russell Giddings
by
5.1k points