filmov
tv
Can you choose the right option? Python Interview question part2. #programming #coding #python #java

Показать описание
Answer: A) 8 10
Explanation:-
In this code snippet, outer_function is a higher-order function that returns another function inner_function. When outer_function is called with an argument x, it creates a closure over x and returns inner_function, which can access x.
We then create two new functions add_five and add_ten by calling outer_function with arguments 5 and 10 respectively. These functions essentially add 5 or 10 to their input argument.
When we call add_five(3), it invokes the inner_function with x as 5 (captured from the closure) and y as 3, resulting in 5 + 3 = 8. Similarly, add_ten(3) invokes inner_function with x as 10 and y as 3, resulting in 10 + 3 = 13.
Therefore, the correct output is Option A) 8 13.
#programming ,#programmer ,#python ,#c ,#java ,#javascript ,#webdevelopment ,#computer ,#computerscience #internship #job #chatgpt #ai #openai
Explanation:-
In this code snippet, outer_function is a higher-order function that returns another function inner_function. When outer_function is called with an argument x, it creates a closure over x and returns inner_function, which can access x.
We then create two new functions add_five and add_ten by calling outer_function with arguments 5 and 10 respectively. These functions essentially add 5 or 10 to their input argument.
When we call add_five(3), it invokes the inner_function with x as 5 (captured from the closure) and y as 3, resulting in 5 + 3 = 8. Similarly, add_ten(3) invokes inner_function with x as 10 and y as 3, resulting in 10 + 3 = 13.
Therefore, the correct output is Option A) 8 13.
#programming ,#programmer ,#python ,#c ,#java ,#javascript ,#webdevelopment ,#computer ,#computerscience #internship #job #chatgpt #ai #openai