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 IS 10/11 × 3/7 × 1/2???​
Read the excerpt from "The Crab That Played with the Sea.” He went North, Best Beloved, and he found All-the-Elephant-there-was digging with his tusks and stamp
During a total solar eclipse, the Earth, Sun, and Moon are arranged in a line, and almost all of the Sun's light traveling to the Earth is blocked by the Moon.
What goals are you willing to implement over the next 90 days to save money? Remember a goal without a due date is a wish
After Santa Anna was captured, Mexico agreed to
Find the area of the triangle. a. 620 sq. m b. 270 sq. m C. 540 sq. m d. 980 sq.m
cot x sin x = cos x?
Jasmine hangs a painting in the middle of a wall of the store. The wall 18 1/4 feet long. The painting is 5 1/4 feet wide and 9 1/2 feet tall. She estimates tha
easy multiplication question ;)
X ^7 x x^9 using a^b