+ 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
4 Respuestas
+ 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.
+ 2
Kuba Siekierzyński very clear 😃 thank u sooo much 💐
+ 1
where did you get the code from?
and where did 132 come from?
+ 1
that explained everything😁