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
What outline feature can the Navigation pane browse the document by?
sattari [20]
It can browse the document by headings.
5 0
2 years ago
Read 2 more answers
If you use a surrogate key, you must ensure that the candidate key of the entity in question performs properly through the use o
Colt1911 [192]
Hello  <span>Abigailguzman6347</span><span>


</span>Answer: If you use a surrogate key, you must ensure that the candidate key of the entity in question performs properly through the use of "unique index" and "not null" constraints.

Hope This Helps!
-Chris
6 0
3 years ago
Write a method swaparrayends() that swaps the first and last elements of its array parameter. ex: sortarray = {10, 20, 30, 40} b
Alexus [3.1K]
In the C programming language, you can't determine the array size from the parameter, so you have to pass it in as an extra parameter. The solution could be:

#include <stdio.h>

void swaparrayends(int arr[], int nrElements)
{
int temp = arr[0];
arr[0] = arr[nrElements - 1];
arr[nrElements - 1] = temp;
}


void main()
{
int i;
int myArray[] = { 1,2,3,4,5 };
int nrElements = sizeof(myArray) / sizeof(myArray[0]);
swaparrayends(myArray, nrElements);

for (i = 0; i < nrElements; i++)
{
printf("%d ", myArray[i]);
}

getchar();
}

In higher languages like C# it becomes much simpler:

        static void Main(string[] args)
        {
            int[] myArray = {1, 2, 3, 4, 5};
            swaparrayends(myArray);
            foreach (var el in myArray)
            {
                Console.Write(el + " ");
            }

            Console.ReadLine();
        }

        static void swaparrayends(int[] arr)
        {
            int temp = arr[0];
            arr[0] = arr.Last();
            arr[arr.Length - 1] = temp;
        }

3 0
3 years ago
When parking ur vehicle facing downhill with a curb, you should point ur front wheels?
Genrish500 [490]
Wheels should be pointing towards the curb. this is in case your vehicle rolls, if it does, the wheel will hit the curb and stop the car, it will also prevent the car from going into the road and incoming traffic. vice versa when parking uphill, point wheels away from curb, that is also to prevent the car from rolling to incoming traffic.
6 0
3 years ago
Read 2 more answers
If you use your smartphone as a hotspot to connect to the Internet on your tablet you are using a ________.quillet
Nataly [62]
Personal Area Network
7 0
2 years ago
Other questions:
  • To use files in a c++ program you must include the ________ header file.
    15·1 answer
  • In most software packages, the function key F1 is used to run the _____program.
    10·1 answer
  • According to the "multiple-selves" theory, of an online DVD rental service could offer same-day deliveries, so that people who o
    9·1 answer
  • Explain any 10uses of computer that are specific to your field of study giving appropriate examples​
    13·1 answer
  • 1. Trust can be built in a relationship if:
    15·1 answer
  • Pls help I will give points
    7·1 answer
  • 1. Which sentence best expresses the main idea
    12·1 answer
  • Imagine a machine that produces an output force that is five times larger
    11·1 answer
  • Which of these is not the correct method for moving text in a document in Word 2016?
    5·1 answer
  • Using C++
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!