What is the output of the following function calldef outer_fun(a, b): def inner_fun(c, d): return c + d return inner_fun(a, b) return a result = outer_fun(5, 10)print(result)515(15, 5)Syntax Error
Question
What is the output of the following function calldef outer_fun(a, b): def inner_fun(c, d): return c + d return inner_fun(a, b) return a result = outer_fun(5, 10)print(result)515(15, 5)Syntax Error
Solution
The output of the function call will be 15.
Here's the step by step explanation:
- The function
outer_funis defined with two parametersaandb. - Inside
outer_fun, another functioninner_funis defined with two parameterscandd. inner_funreturns the sum ofcandd.outer_funreturns the result of callinginner_funwithaandbas arguments.- When
outer_funis called with5and10as arguments,inner_funis called with5and10. inner_funreturns the sum of5and10, which is15.- This result is then returned by
outer_fun, soresultis15. - When
resultis printed, it outputs15.
Similar Questions
What is the output of the following code?def outer_fun(a, b): def inner_fun(c, d): return c + d return inner_fun(a, b) res = outer_fun(5, 10)print(res)
What does the following code do? def outer(x): def inner(y): return x * y return inner f = outer(5) print(f(2)) print(f(3)) print(outer(4)(2)) 10, 15, 810, 15, 2010, 15, 8, 810, 15, 20, 8
What is the output of the following function calldef fun1(name, age=20): print(name, age) fun1('Emma', 25)
What is the output of the following code snippet?def apply_func(L, func): return [func(x) for x in L]apply_func([7.1, 17.9], lambda x: x**3)
If you assign the result a void function to a variable in Python, you get:
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.