We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Number Sum

In this chapter we are going to hammer down the concepts we've learned by running through a bunch of practice problems without introducing any new concepts.

Assignment

Complete the number_sum function. It should add up all the numbers from 1 to n and return the result. If n is less than 1, return 0. For example:

  • number_sum(5) -> 1+2+3+4+5 -> 15
  • number_sum(3) -> 1+2+3 -> 6

Remember that a range will not include the last number.