Unit 2 Task 45: Sum of squares pyramid

Learn to code with step-by-step lessons. A place for students to work through programming fundamentals and build skills.

Unit 2 Task 45 - Sum of squares pyramid

← Unit 2 tasks · Solution


Stack n layers of blocks: layer k uses blocks. The total for n layers is 1² + 2² + … + n².

Ask for n, compute with a loop, print the total.

Skills: for, squaring in loop.

Example: n = 3 → 1 + 4 + 9 = 14.