+ 1
def add(x, y): return x + y def do_twice(func, x, y): return func(func(x, y), func(x, y)) a = 5 b = 10 print(do_twice(add, a, b))
Please explain step by step Which is caller here? Explain the 3rd and 4th line ? why in 4th line we write add(add(x,y),add(x,y)) which is function of 1st line ? how can we write function after return statement insted of (x+y+x+y )=30?
6 Respuestas
+ 4
see..def add(x,y): #you defined your function here.
  #in which x and y are parameters.
   return x+y #a return statement.
  #after it not a statement will get executed.
  def do_twice(func,x,y):
      return func(func(x,y),func(x,y))
#another func. is defined.but,'func' is the difference.
#'func' is used as a parameter to call a func. later.
   a=5 
   b=10  #let's skip it.
  print(do_twice(add,a,b)#a function print.
  #in which,do_twice is 'called'.
  #and add,a,b are the arguments for parameters.
  #thus,do_twice will get executed.as defined.
  #return add(add(5,10),add(5,10))
  #add (5,10)=15.thus,add(15,15)=30.
  #we have return statement.thus,we can use this ..
  #value outside the def. func. too.it will return 30 
  #which will print 30.
 note- after 'return' statement nothing is executed.
 
+ 1
No i was not asking that.
Please read carefully what i have written below
0
какието непонятные примеры кода и без обьяснения логики - удаляю приложение
0
why this func is  adding the (a,b)
 do_twise func (func(x,y),func(x,y))
if i remove the func 
it's print result
5,10,5,10
0
Can someone help me with this 
def add_it(.....  ,.....  )
return..........
print(add_it(5,6))
I need to fill the Voids with this y , 6, x, z, 11, 5
Thanks for everything 🙂
y , 6, x, a,11,5,
- 1
Maybe you're asking "Recursion"
add(add(5,10),add(5,10)
->add(15,15)
->30
OR
ans=0
for i in range(2):
    ans += add(a,b)



