Print Cubes from 1 to N

Print cube of each number from 1 to n.

Logic BuildingIntermediate
Logic Building
# Take n
n = int(input("Enter n: "))

# Print cubes
for i in range(1, n + 1):
    print(f"{i}³ = {i * i * i}")

Output

Enter n: 5
1³ = 1
2³ = 8
3³ = 27
4³ = 64
5³ = 125

Calculate and print cube of each number.

Key Concepts:

  • Loop from 1 to n
  • Calculate i * i * i for each
  • Print formatted output