[Tutor] product of all arguments passed to function call
Manprit Singh
manpritsinghece at gmail.com
Mon May 31 05:56:21 EDT 2021
Dear sir ,
Consider a problem where i have to find the product of all arguments passed
to function call , where the function must be capable of accepting any
number of arguments : My approach will be as follows :
def product(x, *y):
for ele in y:
x *= ele
return x
ans = product(3, 4, 2)
print(ans) gives the right answer = 24
ans = product(3, 4, 2, 5)
print(ans) gives the right answer = 120
The point here is, in both cases, 3 is the first argument which will be
passed to formal parameter x, and rest of the arguments will be received by
y in the form of tuple. Is my understanding correct? is my problem solving
correct in this case ?
Regards
Manprit Singh
More information about the Tutor
mailing list