KnowledgeBoat Logo

Computer Science

Consider the following Python function Fn(), that follows:

def Fn(n):
   print (n, end=" ")
   if n < 3:
      return n
   else:
      return Fn (n//2) - Fn (n//3)

What will be the result produced by the following function calls?

  1. Fn (12)
  2. Fn (10)
  3. Fn (7)

Python

Python Functions

1 Like

Answer

1.

12 6 3 1 1 2 4 2 1 

2.

10 5 2 1 3 1 1 

3.

7 3 1 1 2 

Working

The provided code defines a recursive function Fn(n) that prints the value of n and then checks if n is less than 3. If n is less than 3, the function returns n. Otherwise, it recursively calls itself with n//2 (integer division by 2) and subtracts the result of another recursive call with n//3 (integer division by 3).

Answered By

1 Like


Related Questions