49.8k views
1 vote
Assume in the for loop header, the range function has the three arguments: range (1, 10, 3), if you were to print out the value of the variable

in the for loop header, what will be printed out? List the values and separate them with a comma.

User Edgar H
by
5.0k points

1 Answer

4 votes

Answer:

1, 4, 7

Step-by-step explanation:

The instruction in the question can be represented as:

for i in range(1,10,3):

print i

What the above code does is that:

It starts printing the value of i from 1

Increment by 3

Then stop printing at 9 (i.e.. 10 - 1)

So: The sequence is as follows

Print 1

Add 3, to give 4

Print 4

Add 3, to give 7

Print 7

Add 3, to give 10 (10 > 10 - 1).

So, it stops execution.

User Monojohnny
by
5.5k points