Python Practice › Loop Programs › Program 5
Print 0 to 6 except 3 and 6
Write a Python program that prints all the numbers from 0 to 6 except 3 and 6.
Output
0 1 2 4 5
Approach
- Use
continueto skip the unwanted numbers.
Solution
for n in range(7): if n in (3, 6): continue print(n, end=" ")print()Output
0 1 2 4 5
Line by line
Lines 2-3
continue jumps to the next number, so 3 and 6 are never printed.
Learn the concept
New to this topic? Read the lesson, then come back.