Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
Example code in āFunctional Programmingā
I donāt get this code. Why does the answer come out to be 20? If you pass the value from the first function to the second function, you donāt get an answer of 20! Can someone please explain this to me?
5 Respostas
+ 2
It does return 15 from the inner function:
add_five(add_five(10))
== add_five(10+5)
== add_five(15)
== 15+5
== 20.
+ 1
Are you talking about the code in the first slide?
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2459/
0
yes... shouldnāt this return 15 from the second funtion and then twice that, from the first function, for a total of 30?
what am i getting wrong?
0
got that... what about āapply_twiceā ?
doesnt that function double the value returned from āadd_fiveā?
seems to me that that would be 30...
0
You can do what's called substitution.
apply_twice is defined as `func(func(arg))`.
But then, when we call apply_twice, you can in your head substitute the arguments: `func` becomes `add_five` and `arg` becomes `10`.
So `func(func(arg))` becomes `add_five(add_five(10))` and then we are at where Diego Acero started off.