1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Temka [501]
3 years ago
13

Write a program that prints all the numbers from 0 to 6 except 3 and 6. Expected output: 0 1 2 4 5

Computers and Technology
1 answer:
stellarik [79]3 years ago
8 0
<h2>Answer:</h2><h2></h2>

for x in range(7):

   if (x == 3 or x==6):

       continue

   print(x, end=' ')

print("\n")

<h2>Output:</h2>

>> 0 1 2 4 5

<h2>Explanation:</h2><h2></h2>

The code above has been written in Python. The following explains each line of the code.

<em>Line 1:</em> for x in range(7):

The built-in function <em>range(7)</em>  generates integers between 0 and 7. 0 is included but not 7. i.e 0 - 6.

The for loop then iterates over the sequence of number being generated by the range() function. At each iteration, the value of x equals the number at that iteration. i.e

For the first iteration, x = 0

For the second iteration, x = 1

For the third iteration, x = 2 and so on up to x = 6 (since the last number, 7, is not included).

<em>Line 2:</em> if (x == 3 or x == 6):

This line checks for the value of x at each iteration. if the value of x is 3 or 6, then the next line, line 3 is executed.

<em>Line 3:</em> continue

The <em>continue</em> keyword is used to skip an iteration in a loop. In other words, when the continue statement is encountered in a loop, the loop skips to the next iteration without executing expressions that follow the <em>continue</em> statement in that iteration. In this case, the <em>print(x, end=' ')  </em>in line 4 will not be executed when x is 3 or 6. That means 3 and 6 will not be printed.

<em>Line 4:</em> print(x, end=' ')

This line prints the value of x at each iteration(loop) and then followed by a single space. i.e 0 1 2 ... will be printed. Bear in mind that 3 and 6 will not be printed though.

<em>Line 5:</em> print("\n")

This line will be printed after the loop has finished execution. This line prints a new line character.

You might be interested in
1.
Brums [2.3K]

Answer:

as

is so good

Explanation:

7 0
2 years ago
Write a two to three sentence response to the following question:
nlexa [21]

Answer:

Functions can be useful for many reasons, it is one of the main components to learn in writing code. Without functions code would not be where it is today.

Explanation:

5 0
2 years ago
Enzo is writing a paper about the similarities and differences between ancient Rome and modern America. Which text structure is
GenaCL600 [577]

Answer:

The correct answer is <em><u>B.) comparison and contrast</u></em>

Explanation:

just did the unit test review. you are welcome

4 0
3 years ago
Read 2 more answers
True or false? Resistors regulate and limit electrical current. A. True B. False
Vikki [24]
Hello! I believe the answer for this is "True"!
3 0
3 years ago
Read 2 more answers
My ar goal is 16.3 what percent am i at if i have 3 points??
Mazyrski [523]

24 percent so far so keep working at that goal

5 0
3 years ago
Other questions:
  • when you create workplace documents, it is most important to ensure that they are clear, professional, and a. short. b. informal
    7·1 answer
  • Your laptop doesn't have a serial port. what type of connector will your laptop require
    6·1 answer
  • How read binary file in c++
    7·1 answer
  • Can someone help me with this one
    9·2 answers
  • A coworker asks your opinion about how to minimize ActiveX attacks while she browses the Internet using Internet Explorer. The c
    14·1 answer
  • is used to reduce the chance of an individual violating information security and breaching the confidentiality, integrity, or av
    6·1 answer
  • Hi whats airpods good for
    15·2 answers
  • Last bittttt of points
    8·1 answer
  • Why computer manufacturers constantly releasing faster computers ?
    14·1 answer
  • Why is it important for organizations to make strong commitment to Cloud at scale?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!