Sum of Cubes
Calculate sum of cubes 1³ + 2³ + ... + n³.
IntermediatePhase 6 - Category 4: Mathematical CombinationsExample 2 of 10
sum-of-cubes.py
1# Take n2n = int(input("Enter n: "))34# Calculate sum of cubes5total = 06for i in range(1, n + 1):7 total += i * i * i89print(f"Sum of cubes: {total}")
Output
Enter n: 5 Sum of cubes: 225
What's going on
Sum cubes of numbers from 1 to n.
Key Concepts:
Loop from 1 to n
Calculate i * i * i
Accumulate sum
🔗Related Content
- 📖
Phase 6 - Learn Concepts
Review Phase 6 concepts and explanations
- 📝
Phase 6 - Quiz
Test your Phase 6 understanding with quiz questions
- 💻
Phase 6 - All Practice Problems
Explore all practice problems for Phase 6
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum