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

Write 1.48 repeating as a mixed number
How did social and economic life change for freed people
What's 0.277 rounded to the nearest hundreds
Why were the Appalachian mountains important to the colonies?
you've located three books on a topic you;re researching for an essay. The first thing you should do in determining if any of these books will be useful
what wattage is a toaster that uses 5 amps from a 120 volt outlet
expended form 605,970
Which of the following best describes why the Farmers’ Alliances formed the Populist Party? A) The Farmers’ Alliances were not successful in changing the crop-l
Which statements describe factors that led to the decline and defeat of the Aztec Empire? Choose all answers that are correct. A. The Aztecs had never seen stee
What are some interesting facts about the Quapaw Indians