Functional Programming | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Functional Programming

def apply_twice(func, arg): return func(func(arg)) def add_five(x): return x + 6 print(apply_twice(add_five, 11)) Why output is 23? It should be 22.

14th Sep 2020, 7:21 AM
Jash Sampat
5 Answers
+ 5
The control flow is something like this- 1. add_five receives 11 and add_five. 2. It has return statement with branched function call. func(func(arg)) = func(17) (it adds 6 to 11) func(17) = 23 (it adds 6 to 17)
14th Sep 2020, 7:31 AM
Charitra
Charitra - avatar
+ 9
Why would you call a function that adds 6 "add_five"? Variable names should help the readers not confuse them 🙃
14th Sep 2020, 9:50 AM
David Ashton
David Ashton - avatar
+ 6
David Ashton à la SL quiz. :>
14th Sep 2020, 10:36 AM
Hatsy Rei
Hatsy Rei - avatar
+ 6
Hatsy Rei Hmm Jash's question is the same as https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2459/ first lesson except there add_five() returns x + 5 and the argument is 10 not 11. I couldn't find the quiz (?)
15th Sep 2020, 3:18 AM
David Ashton
David Ashton - avatar
+ 1
Everyone don't work as per their names. It's name is add_five but it actually adds 6.😜😀😀 Just like Kushboo naam ki ladki bhi badbu lagti hai 😜😂😂😎
17th Sep 2020, 12:33 PM
Manu