Sum of n numbers

Easy
32
1
86.0% Acceptance

In this lab, you will write a Python function named sum_of_n. This function should calculate the sum of all integers from 1 up to a given positive integer n.

Function Requirements:

  • The function should be named sum_of_n.
  • It should take one argument, n, which is a positive integer.
  • The function should return the sum of all integers from 1 to n.

Examples:

  1. If you call sum_of_n(3), the function should return 6, as 1 + 2 + 3 = 6.
  2. For sum_of_n(5), the expected output is 15, since 1 + 2 + 3 + 4 + 5 = 15.

Task:
Write the sum_of_n function following the above requirements. Ensure your function passes all the challenges by calculating the correct sums for different values of n.