Python Exercise: Prints all the numbers from 0 to 6 except 3 and 6
Python Conditional: Exercise-8 with Solution
Write a Python program that prints all the numbers from 0 to 6 except 3 and 6.
Note : Use 'continue' statement.
# 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")
0 1 2 4 5
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.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join