+ 2
HELP ME WITH THIS CODE
IF WE WILL take three arguments instead of two then how will this code looks and what changes we should make into it https://code.sololearn.com/c73ID5HzqsE7/?ref=app
7 Answers
+ 1
#IF WE WILL TAKE THREE ARGUMENTS x,y,z THEN HOW CAN WE SOLVE THIS.
def add(x,y,z):
return x + y + z
def do_twice(func,x,y,z):
return func(func(x,y,z),func(x,y,z),func(x,y,z))
a = 78
b = 5
c = 10
print(do_twice(add,a,b,c))
+ 2
Jayakrishna🇮🇳 THANKS BROO I GOT ANSWER. BUT I DON'T KNOW ABOUT *kwarg FUNCTION BUT REALLY APPRECIATE YOUR ANSWER THANKS FOR HELP.
+ 1
Add one more patameter as you added 2 => x, y .
Or
else, use *arg variable arguments *for any number of argument passing........ *
def add(x,y, *arg):
return x + y+sum(arg)
def do_twice(func,x,y,*arg):
return func(func(x,y,*arg),func(x,y,*arg))
a = 78
b = 5
c = 4
print(do_twice(add,a,b,c))
print(do_twice(add,1,2,3,4,5,7,8,9))
edit:
*arg takes any variable number of arguments..
https://www.digitalocean.com/community/tutorials/how-to-use-args-and-kwargs-in-JUMP_LINK__&&__python__&&__JUMP_LINK-3
+ 1
Mohammadmehdi Karami THANKS I JUST GOT IT BY LOOKING CODE AGAIN. AND YOUR EXPLANATION IS SANE AS ME. THANK YOU VERY MUCH
+ 1
It's an alternative. IDIOT KID
I added in explanation, the other way but it is already answered when I see after my post..
Hope this helps to know more if you want about *arg, and **kwarg.
I mean actually *arg => variable number of argument pass.. I edited it see again..
https://www.digitalocean.com/community/tutorials/how-to-use-args-and-kwargs-in-JUMP_LINK__&&__python__&&__JUMP_LINK-3
hope it helps..
you're welcome...
0
def add(*arg):
return sum(arg)
def do_twice(func,*arg):
return func(func(*arg), func(*arg))
a=6
b=7
c=9
d=15
print(do_twice(add,a,b,c,d))
0
)+?&?++€#2?