As @georg suggested, you should use *args
to specify a function can take a variable number of unnamed arguments.
args
feeds the function as a tuple. As an iterable, this can be accepted directly by Python’s built-in sum
. For example:
def sum_it_up(*args):
print('The total is {0}'.format(sum(args)))
sum_it_up(1,4,7,10) # The total is 22
sum_it_up(1,2,0,0) # The total is 3
0
solved function (sum_it_up) that takes any number of parameters and returns to sum