Print Cubes from 1 to N

Print cube of each number from 1 to n.

IntermediatePhase 2 - Level 3: Mathematical & Logical PatternsExample 2 of 13
print-cubes-from-1-to-n.py
1# Take n
2n = int(input("Enter n: "))
3
4# Print cubes
5for i in range(1, n + 1):
6 print(f"{i}³ = {i * i * i}")

Output

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

What's going on

Calculate and print cube of each number.

Key Concepts:

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