Programs · Program 6-8
Q.Program 6-8: Program to print even numbers in a given sequence using for loop.
Yanam CbseNCERTSubjective· 2mImportance★★★★★est
31% · 12/39 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Combine iteration with selection: the loop visits every number of the sequence, and an if num % 2 == 0: filter lets only the even ones through to print().
The idea. This program demonstrates the loop + filter pattern — a for loop supplies every element, and an if inside the body decides which elements to act on. The evenness test uses the modulus operator: num % 2 is the remainder when num is divided by 2, which is 0 exactly for even numbers.
# Program 6-8: print the even numbers in a given sequence
sequence = [3, 8, 15, 22, 7, 40, 9, 12]
for num in sequence:
if num % 2 == 0:
print(num, "is an even number")
Expected output
8 is an even number
22 is an even number
40 is an even number
12 is an even number
How it works
- The loop takes the elements in order: 3, 8, 15, 22, 7, 40, 9, 12.
- For 3,
3 % 2is1→ the condition is False → nothing is printed; for 8,8 % 2is0→ True → the line is printed. The same test filters the rest. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.