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

whats a medium in art? its for an art project
The size of your pool cover distance or area
A poll predicted that 68% of voters plan to vote for the current mayor in the upcoming election. If the poll had a standard deviation of 4%, what is the margin
How can water return to Earth from the atmosphere?
Which nazi leaders helped push germany toward greater anti-semitism and racism, leading to the holocaust? check all that apply.
7.4 Practice A In Exercises 1-5, the diagonals of rhombus ABCD intersect at E. Given that mZEAD - 67', CE - 5, and DE 12, find the indicated measure. 1. MZAED 5
5. Simplify: 40,100/20
Monomials. Pls hurry. I have a test. (3p^7)^4
2) The population of a small country grows according to the function P(t) = 1,300,000e0.05t, where t is measured in years. In how many years will the population
A square has a diagonal of length 12. Find the length of each side.