Functional Programming | Sololearn: Learn to code for FREE!

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.

9/14/2020 7:21:54 AM

Jash Sampat

5 Answers

New Answer

+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)

+9

Why would you call a function that adds 6 "add_five"? Variable names should help the readers not confuse them 🙃

+6

Hatsy Rei Hmm Jash's question is the same as https://www.sololearn.com/learn/Python/2459/ first lesson except there add_five() returns x + 5 and the argument is 10 not 11. I couldn't find the quiz (?)

+5

David Ashton à la SL quiz. :>

+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 😜😂😂😎