Count even numbers in tuple Dry Run in PYTHON

Count even numbers in tuple is an interactive PYTHON dry run visualizer from the Tuples 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 tuple Program Code

# Count even numbers in tuple
numbers = (14, 9, 26, 48, 33, 20, 11, 58, 43, 40, 29)
print("Tuple:", 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 list comprehension
even_count_comp = sum(1 for num in numbers if num % 2 == 0)
print(f"Using comprehension: {even_count_comp}")

View the complete Tuples programs page.

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