Computer Science, asked by cpsanjeev578, 7 months ago

Predict the output of the following python program: r = lambda q: q * 2 s = lambda q: q * 3 x = 2 x = r(x) x = s(x) x = r(x) print x *

Answers

Answered by praneetgopnarayan2
0

Explanation:

r and s are lambda functions or anonymous functions and q is the argument to both of the functions. In first step we have initialized x to 2. In second step we have passed x as argument to the lambda function r, this will return x*2 which is stored in x. That is, x = 4 now. Similarly in third step we have passed x to lambda function s, So x = 4*3. i.e, x = 12 now. Again in the last step, x is multiplied by 2 by passing it to function r. Therefore, x = 24.

Answered by HrishikeshSangha
0

The output of the given Python program would be 72.

Here's how the output is obtained:

  • First, we define two lambda functions r and s, which multiply their input by 2 and 3 respectively.
  • We then assign the value 2 to the variable x.
  • Next, we call the lambda function r with x as the argument. This sets the value of x to 4 (2 * 2).
  • We then call the lambda function s with x as the argument. This sets the value of x to 12 (4 * 3).
  • Finally, we call the lambda function r with x as the argument. This sets the value of x to 24 (12 * 2).
  • We then print the value of x multiplied by an implicit 1, which gives us the final output of 72 (24 * 1).

For further reference visit,

https://brainly.in/question/54933613?referrer=searchResults

https://brainly.in/question/12929885?referrer=searchResults

#SPJ3

Similar questions