Knowee
Questions
Features
Study Tools

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

Question

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

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

Solution

The correct answer is Infinite loop.

Here's why:

The function demo(x) is a recursive function, which means it calls itself within its own definition.

When you call demo(45), the condition x > 100 is not met because 45 is not greater than 100. So, it goes to the next line return demo(demo(x+11)).

This means it will call demo(56). Again, 56 is not greater than 100, so it calls demo(67). This process continues indefinitely because the condition x > 100 is never met.

Therefore, the function will keep calling itself infinitely, resulting in an infinite loop.

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

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))

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

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

Select the correct answerWhat will be the output of the following Python code snippet if x=1?x<<2Options1248

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.