Print Cubes from 1 to N
Display cubes from one through n with a for loop. Beginners trace three-factor multiplication and distinguish a printed power label from executable arithmetic.
1# Take n2n = int(input("Enter n: "))34# Print cubes5for 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
In this one
- Build a cube with multiplication
- Include the endpoint
- Separate notation from arithmetic
How it works
- 1
Visit one through n.
- 2
Multiply i by itself three times.
- 3
Print the original value beside its cube.
Edge cases
Is n included?
Is n included?
Yes, when n is positive.
What if n is negative?
What if n is negative?
The range is empty; this example does not report invalid input.
What's going on
A cube multiplies a number by itself three times. i * i * i calculates it for each visited integer.
The f-string pairs the original value with its cube. For three, that result is twenty-seven. range excludes its stopping bound, so adding one to n includes the requested endpoint without an extra iteration.
Is n included? Yes, when n is positive.
What if n is negative? The range is empty; this example does not report invalid input.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
What is printed for i = 2?
Pick an answer to check it.
Question 2
Is n included?
Pick an answer to check it.
Questions people ask
Is n included?
Yes, when n is positive.
What if n is negative?
The range is empty; this example does not report invalid input.
What is printed for i = 2?
8.
🔗Related Content
- 📖
Phase 2 - Learn Concepts
Review Phase 2 concepts and explanations
- 📝
Phase 2 - Quiz
Test your Phase 2 understanding with quiz questions
- 💻
Phase 2 - All Practice Problems
Explore all practice problems for Phase 2
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum