Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Question: Write a Python program to find the factorial of a number.
Answer:

def factorial(n):

  return 1 if n == 0 else n * factorial(n-1)

Example:

factorial(5)  # Output: 120
Is it helpful? Yes No

Most helpful rated by users:

©2025 WithoutBook