w3resource

Python Exercise: Prints all the numbers from 0 to 6 except 3 and 6


8. Print Numbers 0 to 6 Except 3 and 6

Write a Python program that prints all the numbers from 0 to 6 except 3 and 6.

Note : Use 'continue' statement.

Pictorial Presentation:

Python Exercise: Prints all the numbers from 0 to 6 except 3 and 6

Sample Solution:

Python Code:

# Iterate through numbers from 0 to 5 using the range function
for x in range(6):
    # Check if the current value of 'x' is equal to 3 or 6
    if (x == 3 or x == 6):
        # If 'x' is 3 or 6, skip to the next iteration without executing the code below
        continue
    # Print the value of 'x' with a space and without a newline (end=' ')
    print(x, end=' ')

# Print a new line after printing all numbers satisfying the condition
print("\n")
	

Sample Output:

0 1 2 4 5 

Flowchart:

Flowchart: Python program that prints all the numbers from 0 to 6 except 3 and 6

For more Practice: Solve these Related Problems:

  • Write a Python program to print numbers from 0 to 6 but skip 3 and 6 using the continue statement in a loop.
  • Write a Python program to filter numbers from 0 to 6 using list comprehension that excludes 3 and 6.
  • Write a Python program to iterate over a range and conditionally print values except for those equal to 3 or 6.
  • Write a Python program to create a list of numbers from 0 to 6 that omits 3 and 6 and then print it.

Go to:


Previous: Write a Python program that prints each item and its corresponding type from the following list.
Next: Write a Python program to get the Fibonacci series between 0 to 50.

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.