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

For which purpose would a thematic map be most appropriate?
what is unit in physics ​
7. Which of the following statements is NOT true? a. All integers are rational numbers. b. Some rational numbers are whole numbers. c. All whole numbers are nat
How do we know that Tomas Jefferson when he wrote the words “all men are created equal” did not understand the meaning of equal? A. Because of the bills he woul
a square courtyard has sides that are 10 ft long what is the courtyard area
What types of hydrogen atoms have the potential to form van der waals interactions?
Plants need what that animals exhale
The ocean floor is which ocean zone? * a) Aphotic b) Benthic c) Intertidal d) Photic
: Which of the following is produced during the formation of photochemical smog ? ...
how do you write 3 hundredths