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

Dictionary of cubes (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 cubes (1 to n) Program Code

# Create dictionary of cubes (number: cube)
n = 8
cubes = {x: x**3 for x in range(1, n+1)}
print(f"Cubes from 1 to {n}:")
for num, cube in cubes.items():
    print(f"  {num}³ = {cube}")

# For odd numbers only
odd_cubes = {x: x**3 for x in range(1, n+1) if x % 2 != 0}
print(f"\nOdd numbers cubes: {odd_cubes}")

# Using loop
cubes_loop = {}
for i in range(1, 9):
    cubes_loop[i] = i**3
print(f"\nLoop result: {cubes_loop}")

View the complete Dict programs page.

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