Dictionary of squares (1 to n) Dry Run in PYTHON

Dictionary of squares (1 to n) is an interactive PYTHON dry run visualizer from the Dict 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.

Dictionary of squares (1 to n) Program Code

# Create dictionary of squares (number: square)
n = 10
squares = {x: x**2 for x in range(1, n+1)}
print(f"Squares from 1 to {n}:")
for num, sq in squares.items():
    print(f"  {num}² = {sq}")

# Using loop
squares_loop = {}
for i in range(1, 11):
    squares_loop[i] = i**2
print("\nUsing loop:", squares_loop)

# Only even numbers
even_squares = {x: x**2 for x in range(2, 11, 2)}
print(f"\nEven numbers squares: {even_squares}")

View the complete Dict programs page.

Program Console Dictionary of squares (1 to n) Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.