Professional Documents
Culture Documents
Nested
Nested
fun(95)
def fun(n):
if(n > 100): // if the condition is false, it will proceed to the last line of code
return n – 10 // 96
106
return fun(fun(n + 11)) // adds the value of n by 11, and pass it onto the if-statement, so
the
code looks like if(106 > 100) which is actually true and then it will
execute the next line of code which now returns 96 by subtracting 10.
The number 96 will be the new value of fun(n).
The same goes as follows;
fun(96)
def fun(n):
if(n > 100): // if the condition is false, it will proceed to the return function
return n – 10 // 97
107
return fun(fun(n + 11))
fun(97)
def fun(n):
if(n > 100): // if the condition is false, it will proceed to the last line of code
return n – 10 // 98
108
return fun(fun(n + 11))
fun(98)
def fun(n):
if(n > 100): // if the condition is false, it will proceed to the return function
return n – 10 // 99
109
return fun(fun(n + 11))
fun(99)
def fun(n):
if(n > 100): // if the condition is false, it will proceed to the return function
return n – 10 // 100
110
return fun(fun(n + 11))
fun(100)
def fun(n):
if(n > 100): // if the condition is false, it will proceed to the return function
return n – 10 // 101
111
return fun(fun(n + 11))
fun(101)
def fun(n):
if(n > 100): // the condition is true, so it will execute next line of code which answers 91 by
subtracting 101 to 10
91
return n – 10
Output:
The output of the example above is 91
The sky blue highlighted text represents as the new value of n in a fun(n).