What will be the output of the following Python program?

def factorial(n):
    if n == 0 or n == 1:
        return 1
    return n * factorial(n - 1)

print(factorial(5))
                        

Options

  • A. 25
  • B. 120
  • C. 60
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. 120

Detailed Explanation

A recursive function calls itself. Here, factorial(5) = 5 × 4 × 3 × 2 × 1 = 120.