Check if a number is prime or not Dry Run in PYTHON

Check if a number is prime or not is an interactive PYTHON dry run visualizer from the For 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 or not Program Code

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

if num <= 1:
    print(f"{num} is NOT a prime number")
else:
    is_prime = True
    for i in range(2, int(num ** 0.5) + 1):
        if num % i == 0:
            is_prime = False
            break
    
    if is_prime:
        print(f"{num} is a PRIME number")
    else:
        print(f"{num} is NOT a prime number")

View the complete For programs page.

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