This guide explains Beginner Checkpoint: Decisions and Repetition through a focused example and practical reasoning. No prior knowledge of this specific operation is required.
Understanding the Concept
This checkpoint combines exclusive decisions, loops, input validation and accumulating results. Solve the task with understandable control flow before exploring shortcuts.
When You Would Use This
Count even and odd integers in a fixed list.
Step-by-Step Example
sample_numbers = [1, 2, 4, 7, 10]
even_count = 0
odd_count = 0
for number in sample_numbers:
if number % 2 == 0:
even_count += 1
else:
odd_count += 1
print("Even:", even_count)
print("Odd:", odd_count)
How the Example Works
Modulo 2 identifies even numbers. The result is three even and two odd values, and every list item contributes to exactly one count.
Example Output
Even: 3
Odd: 2
Try It Yourself
Create a list of seven integers including negatives and verify both counts by hand.
Common Beginner Mistakes
- Forgetting to initialize counters before the loop.
- Writing two unrelated
ifchecks where oneelsemakes the cases exclusive. - Misclassifying negative even values because of incorrect remainder assumptions.
Key Takeaways
- This checkpoint combines exclusive decisions, loops, input validation and accumulating results.
- Modulo 2 identifies even numbers.
- Avoid this mistake: Forgetting to initialize counters before the loop.