Knowee
Questions
Features
Study Tools

Select the correct answerWhat will be the output of the following Python code?def test(i,j): if(i==0): return j else: return test(i-1,i+j)print(test(4,7))OptionsInfinite loop 713 17

Question

Select the correct answerWhat will be the output of the following Python code?def test(i,j): if(i==0): return j else: return test(i-1,i+j)print(test(4,7))OptionsInfinite loop 713 17

🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct answer is 17.

Here's the step-by-step explanation:

  1. The function test is called with the arguments 4 and 7.
  2. Since i is not 0, the function calls itself with the arguments i-1 (which is 3) and i+j (which is 11).
  3. The function is now called with 3 and 11. Again, since i is not 0, the function calls itself with i-1 (which is 2) and i+j (which is 14).
  4. The function is now called with 2 and 14. Again, since i is not 0, the function calls itself with i-1 (which is 1) and i+j (which is 16).
  5. The function is now called with 1 and 16. Again, since i is not 0, the function calls itself with i-1 (which is 0) and i+j (which is 17).
  6. Finally, the function is called with 0 and 17. Since i is 0, the function returns j, which is 17.

So, the output of the code is 17.

This problem has been solved

Similar Questions

Select the correct answerWhat will be the output of the following Python code?def demo(p,q):  if(p == 0):    return q  else:    return demo(p-1,p+q)print(demo(4,5))Options513Infinite loop15

Select the correct answerWhat will be the output of the following Python code?def demo(x):  if (x > 100):    return x - 5  return demo(demo(x+11)); print(demo(45))Options1005074Infinite loop

Select the correct answerWhat will be the output of the following Python code?def fun(n): if (n > 100): return n - 5 return fun(fun(n+11)); print(fun(45))Options7410050Infinite loop

What will be the output of the following code?for i in range(1,5): if i == 3: continue else: print(i,end = " ")Options: Pick one correct answer from below1 2 3 41 2 41 2 3 4 51 2

Select the correct answerWhat will be the output of the following Python code?def example(k = 1, l = 2):    k = k + l    l = l + 1    print(k, l)example(l = 1, k = 2)OptionsAn exception is thrown because of conflicting values3 33 21 2

1/3

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.