90.6k views
0 votes
Review how to write a for loop by choosing the output of this short program.

for counter in range(3):
print(counter * 2)


Please explain it to me, I’m not learning Bc I don’t have a teacher.

User Turion
by
4.5k points

1 Answer

5 votes

Answer:

The output is:

0

2

4

Step-by-step explanation:

First of all, the print statement must be indented with a tab, otherwise it is not part of the for loop.

The range(3) creates an array with values 0,1,2. The variable 'counter' gets those values one after another, and the print statement outputs this value doubled, hence the 0, 2 and 4 output.

Review how to write a for loop by choosing the output of this short program. for counter-example-1
User Arjan
by
5.7k points