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]
4 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]4 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
Software that manages the resources of the computer is called:
AleksAgata [21]
A. Data management software.
6 0
3 years ago
Which of the following is the best example of a manager with a delegator leadership style
monitta
No examples posted but here are a few examples;
Boss will send other employees to meetings in his/her place
Boss will leave other employees in. Charge when he/she is not there for a period of time.
Boss will assign special assignments
5 0
4 years ago
Read 2 more answers
What is the school wifi password trying to do my class work in school on different devices.
lara31 [8.8K]
This cant be answered unless you name your school and someone goes to your school
4 0
3 years ago
Please explain a function in coding.
Julli [10]

Answer:

it is organized reusable code to perform some action

8 0
3 years ago
A programmer must add 1 to the value stored in the int variable sum. One way is given to get you started. Write two more distinc
olganol [36]

Answer:

option 1: sum++

option 2: ++sum

Explanation:

In programming, a variable a container or memory location assigned to a value. The C++ syntax specifies the memory location type of value on the declaration. The major types of variables in C++ are; integer, float, double, char, string, and boolean.

To add 1 to an integer variable, the variable value could be summed with one and assigned to that same variable or '++before' and 'after++' with adds one to the variable before and after the execution of a statement.

4 0
3 years ago
Other questions:
  • Which of the following best describes how computing devices represent information? A. A computer will either represent informati
    9·2 answers
  • Which is the correct process for selecting an entire row in a spreadsheet?
    15·2 answers
  • I want to make a if else statement where I want to make a message. If the input are letters (which it’s not supposed to) then I
    14·1 answer
  • Write a program that gets a single character from the user. If the character is not a capital letter (between 'A' and 'Z'), then
    15·1 answer
  • A small group of travelers is meeting inside an ancient building, and the travelers need access to the Internet using their mobi
    11·1 answer
  • Sadie helman runs a web site for amateur snowboarders. she likes to post videos and music related to snowboarding on her site as
    12·1 answer
  • A company's desire to sell products and services: A. will ultimately lead to its doom. B. explains why the web took off C. can d
    9·2 answers
  • One student will be stationed near you in a coffee shop. The other student will be located two miles away from your school. You
    10·2 answers
  • Please help will give brainliest
    12·1 answer
  • Give one reason why more people prefer to settle in areas of flat land than on steep slopes​
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!