justinflowers03 justinflowers03
  • 02-12-2020
  • Computers and Technology
contestada

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.

Respuesta :

tonb
tonb tonb
  • 02-12-2020

Answer:

The output is:

0

2

4

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.

Ver imagen tonb
Answer Link

Otras preguntas

What military strategy defeated cornwallis at yorktown?
at what point do scientists classify an area's weather as its climate? 1 year ,5 years ,15 years or 30 years
Write in function form X+y=6..?
mike constructed a closed box that measures 2.5 feet long by 3 feet wide by 1.5 feet high. what is the total area of the material mike needs to construct the bo
WHICH EXPRESSION IS EQUIVALENT TO SIN 22 COS 18 + COS 22 SIN 18?
A number is divided by 32 is 96. What is the number?
The net force acting on a 50 kg crate is 0 N. What is the crate's acceleration
why a flat surface of a rectangular prism called faces?
Mario drew a model to represent one third of the space in his bookcase. how could mario draw a model to represent all the space in his bookcase.
which of the following organisms feeds on the largest variety of producers