Any Number of Arguments
Completed
Write total(*nums) that returns the sum of any number of arguments. Read a line of integers and call total(*values); also print total() with no arguments.
Input
One line of integers.
Output
Two lines.
Example
Input
1 2 3 4
Output
10 0
Editor
Python
Hints
*nums collects positional arguments into a tuple.
Solution explanation
*args in a definition packs arguments; *list in a call unpacks them.
Show solution
def total(*nums):
result = 0
for n in nums:
result += n
return result
values = list(map(int, input().split()))
print(total(*values))
print(total())