Question DSA-REC-0003
EasyWhat is the output of this code?
def fact(n):
return 1 if n <= 1 else n * fact(n - 1)
print(fact(5))
- A.
24
- B.
120
- C.
Show answer and explanation
Answer: B
fact(5) = 5 × 4 × 3 × 2 × 1 = 120.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Recursion and Backtracking question
What is the output of this code?
def fact(n):
return 1 if n <= 1 else n * fact(n - 1)
print(fact(5))
24
120
Answer: B
fact(5) = 5 × 4 × 3 × 2 × 1 = 120.
5
720