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

Which state had the highest correctional budget in 2010?
A _____________ is a monomial or the sum or difference of two or more monomials.
¿Cuáles son los cuentos basados en la Isla de la Juventud? (What are the stories based on the Isle of Youth?) Treasure Island Peter Pan Pirates of the Caribbean
Which is NOT a power of Congress? A) Holding hearings on important issues B) Impeachment C) Oversight D) Vetoing bills
Which participant in European exploration is being described below? This country began the Age of Exploration. Its explorers were the first Europeans to journey
questions from chapter 8.rotational of a rigid body
which pair of metals produces the highest voltage and why
Module 1: The Elements of Music Why should we care about the elements of music? Pitch Rhythm It is composed of both the strong, accented pulses as well as th
Crews at the International Space Station are researching the effects of the weightlessness of space on ________. A. Human Body B. Cats and dogs C. Other planets
URGENT!!!!!!!!!!!!!!!!!!