daga dugo
4 months ago

What will be the output? ef fact(num): if num == 0: return 1 else: return _____________________

A. num*fact(num-1)

B. (num-1)*(num-2)

C. num*(num-1)

D. fact(num)*fact(num-1)

Answer: Option A

Solution (By Examveda Team)

Function Name: fact(num) – This is a recursive function intended to compute the factorial of a number.

Base Case: if num == 0: return 1 – This handles the case where factorial of 0 is 1.

Recursive Case: To compute factorial, the function must call itself with (num-1) and multiply it with num.

Correct Expression: return num*fact(num-1) – This is the standard way to compute factorial recursively.

Option B: (num-1)*(num-2) – This does not use recursion and doesn't follow the factorial logic.

Option C: num*(num-1) – This computes only a partial result and not the full factorial.

Option D: fact(num)*fact(num-1) – This results in redundant recursive calls and incorrect logic.

Correct Answer: Option A: num*fact(num-1)

This Question Belongs to Python Program >> Miscellaneous In Python Program

Join The Discussion

Related Questions on Miscellaneous in Python Program