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 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
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
🔗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