Sum of all the integers

Problem Statement

Given a list or sequence of integer values, find their sum.

Input

The first line of input contains a sequence of integer values separated by space.

Output

Print the sum of given integer values.

As is

The boilerplate code is already there to read the input from user as an integer into a variable, in the main() function. Also it calls the sum_of_integers() function, and prints the returned value. Do not edit this code.

To do ✍

sum_of_integers() has one parameter: nums which is a list of integer values. Write code inside the function body to compute the sum of integer values in the given list, and return the sum.

Example 1

Test input

4 8 6 1 0 7 3 0 -8

Test output

21

Explanation

Sum = 4 + 8 + 6 + 1 + 0 + 7 + 3 + 0 + (-8)
    = 21

Useful References

Python Program

# Complete the following function
# Return the sum of integers in nums
def sum_of_integers(nums):



# Boilerplate code - Do not edit the following
def main():
    nums = [int(x) for x in input().split()]
    print(sum_of_integers(nums))

if __name__ == "__main__":
    main()

Test case 1

0
0

Test case 2

-9 -6 -7 -2 -0 9 1 3 2 6 -8
-11

Test case 3

4 8 6 1 0 74 3 0 -8
88
# Complete the following function
# Return the sum of integers in nums
def sum_of_integers(nums):
    return sum(nums)

# Boilerplate code - Do not edit the following
def main():
    nums = [int(x) for x in input().split()]
    print(sum_of_integers(nums))

if __name__ == "__main__":
    main()
show answer
main.py
⏵︎ Run Tests
Reset
Download
×
Code copied to clipboard successfully 👍