+ 5

hello guys can s.one explain for me this code I didn't understand it ! thank u so much nd have a nice day 🤗

def apply_twice(func,arg): return func(func(arg)) def add_10(x): return x_44 print (abs(apply_twice(add_10,_44))) >>>132

31st May 2018, 3:53 AM
molly
4 Antworten
+ 15
The code should actually look like this: def apply_twice(func,arg): return func(func(arg)) def add_10(x): return x+44 print (abs(apply_twice(add_10,44))) What it does: 1. the apply_twice() returns the output of func being applied on arg and then being applied again on the result 2. the add_10() just adds 44 to the argument and returns the value 3. So what happens here is: apply_twice the function of add_10 on an argument of 44 4. So it goes: add_10(add_10(44)) => add_10(44+44) => add_10(88) => (44+88) => 132 abs() just prints the absolute value which does not change anything for positive values.
31st May 2018, 6:16 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 2
Kuba Siekierzyński very clear 😃 thank u sooo much 💐
31st May 2018, 6:20 AM
molly
+ 1
where did you get the code from? and where did 132 come from?
31st May 2018, 6:13 AM
zia
zia - avatar
+ 1
that explained everything😁
31st May 2018, 6:22 AM
zia
zia - avatar