Check if a number is prime Dry Run in PYTHON

Check if a number is prime is an interactive PYTHON dry run visualizer from the While 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.

Check if a number is prime Program Code

# Check if number is prime
num = int(input("Enter a number: "))

if num <= 1:
    print(f"{num} is NOT prime")
else:
    i = 2
    is_prime = True
    while i * i <= num:
        if num % i == 0:
            is_prime = False
            break
        i += 1
    
    if is_prime:
        print(f"{num} is prime")
    else:
        print(f"{num} is NOT prime")

View the complete While programs page.

Program Console Check if a number is prime Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.