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
Using the simple alphabet code below, you will decode and encode the message. Write the Full
gladu [14]

Answer:

acefghijlmb2d4k1113589136510waynopqrtuvx2261415161718202122232425

Explanation:

6 0
3 years ago
What is the best application to create a slide show presentation?
Lynna [10]

Answer:

Microsoft Windows File Manager

5 0
3 years ago
Read 2 more answers
Write a program that prompts the user for an integer, then asks the user to enter that many values. Store these values in an arr
Svetllana [295]

Answer:

//The Scanner class is imported to allow the program receive user input

import java.util.Scanner;

//The class Solution is defined

public class Solution {

   //The main method is defined here and signify the beginning of program execution

   public static void main(String args[]) {

       

       //Scanner object 'scan' is created to receive user input

       Scanner scan = new Scanner(System.in);

       //Prompt display to the user to enter size of array

       System.out.print("Enter the range of array: ");

       //User input is assigned to arraySize

       int arraySize = scan.nextInt();

       //userArray is initialized with arraySize as its size

       int[] userArray = new int[arraySize];

       

       //counter to count number of array element

       int count = 0;

       //while loop which continue executing till the user finish entering the array element

       while (count < arraySize){

           System.out.print("Enter each element of the array: ");

           userArray[count] = scan.nextInt();

           count++;

       }

       

       //A blank line is printed for clarity

       System.out.println();

       

       //for loop to print each element of the array on straight line

       for(int i =0; i <userArray.length; i++){

           System.out.print(userArray[i] + " ");

       }

       

       //A blank line is printed for clarity

       System.out.println();

       

       //for loop is use to reverse the array in-place

       for(int i=0; i<userArray.length/2; i++){

           int temp = userArray[i];

           userArray[i] = userArray[userArray.length -i -1];

           userArray[userArray.length -i -1] = temp;

       }

       

       //for loop to print each element of the reversed array on straight line

       for(int i =0; i <userArray.length; i++){

           System.out.print(userArray[i] + " ");

       }

     

   }

}

Explanation:

The program is commented to give detailed explanation.

The for-loop use in reversing the array works by first dividing the array into two half and exchanging the first half elements with the second half elements. The element from the first half is assigned to temp variable on each loop, then the element is replaced with the equivalent element from the second half. And the element from the second half is replaced with the value of temp.

3 0
3 years ago
The art element line is a moving point.<br><br><br> True or False
sergeinik [125]
I’m pretty sure the answer is true
3 0
3 years ago
Multimedia computer system required the following hardware component they are what​
Lady bird [3.3K]
To develop the system of multimedia we use the various hardware/softwarecomponents are:

The CPU: The CPU, which

is recommended for a multimedia computer should be Pentium IV or other advanced chips. The Monitor: The multimedia PC should be equipped with a monitorhaving Super

Video Graphics Arrays (SVGA) card.

Mark me as brainliest please
3 0
2 years ago
Other questions:
  • To type the letter address, _________ space from the dateline
    9·2 answers
  • Producers must understand the marginal benefit of making an additional unit which shows the ...
    5·2 answers
  • The ____ command creates a subdirectory under a directory. rd md cd ad
    11·1 answer
  • Assume that you have created a class named DemoCar. Within the Main() method of this class, you instantiate a Car object named m
    12·1 answer
  • Which of the following are input devices? Check all that apply.
    9·2 answers
  • What is the best way to use copyrighted material?
    14·2 answers
  • Red + blue =<br>Red + green =<br>Magenta - blue =<br>Yellow - green =<br>Cyan - blue =​
    9·1 answer
  • What are the two types of electronic components
    15·2 answers
  • What refers to a set of instructions executed in order?
    6·1 answer
  • A _______ attack uses software to try thousands of common words sequentially in an attempt to gain unauthorized access to a user
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!