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

how do the geats honor Beowulf after he dies?
What is the value of x in the equation 1/5x - 2/3y =30 when y = 15
How do I solve this expression? (Algebra 1)
HELP ME PLZ I WILL GIVE 10 POINTS OR MORE
What was the importance of the Oregon Trail? It helped Americans reach Spanish missions in the Southwest. It created a road for farmers to migrate to areas wi
A type of technology that can be attached to a tag and used to identify postal packages is a(n) _____.
Which of the following occurred after the Civil War? Question 1 options: Plantation owners lost their free labor. Southern infrastructure was left intac
What are three powers that have values greater than 500 and less than 550
What are three reasons the Declaration of Independence was written?
How many foot-pounds of work does it take to throw a baseball 90 mph? a baseball weighs 5 oz, or 0.3125 lb?