139k views
2 votes
Write a function called sum_first_integers that takes a single positive integer parameter. The function should also return a positive integer. In particular, it should return the sum of the positive integers from 1 to the value passed into the function. For example, if 5 is passed into the function, it should return 15 because that is the number you get when you add 1 + 2 + 3 + 4 + 5.

1 Answer

7 votes

Answer:

Output:

15

Step-by-step explanation:

Below is the program code for the function called sum_first_integers that takes a single positive integer parameter.

def sum_first_integers(n):

total = 0

for i in range(1,n+1):

total += i

return total

# Testing

print(sum_first_integers(5))

Output:

15

User Brian Cristante
by
3.8k points