Count even numbers in set Dry Run in PYTHON

Count even numbers in set is an interactive PYTHON dry run visualizer from the Sets programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Count even numbers in set Program Code

# Count even numbers in set
numbers = {14, 25, 36, 47, 58, 69, 80, 91, 22}
print("Set:", numbers)

# Method 1: Using loop
even_count = 0
even_list = []
for num in numbers:
    if num % 2 == 0:
        even_count += 1
        even_list.append(num)

print(f"Even numbers count: {even_count}")
print(f"Even numbers: {even_list}")

# Method 2: Using comprehension
even_count_comp = sum(1 for num in numbers if num % 2 == 0)
print(f"Using comprehension: {even_count_comp}")

View the complete Sets programs page.

Program Console Count even numbers in set Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.