Python Practice › Loop Programs › Program 5

Print 0 to 6 except 3 and 6

EasyLoop Programs · 5 of 90

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

Advertisement
Output
0 1 2 4 5 

Approach

  1. Use continue to skip the unwanted numbers.

Solution

Python
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.

More loop programs

← All 90 Loop Programs

Leave a Comment