Unit 4 Task 10: Sum from 1 to n

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

Unit 4 Task 10 - Sum from 1 to n

← Unit 4 tasks · Solution


Write sum_to(n) that returns the sum 1 + 2 + … + n for an integer n that is at least 1. Use a loop.

Skills: return, accumulation in a function.