Write a Python function to calculate the factorial of a number


Introduction

Write a Python function to calculate the factorial of a number. I have used python 3.7 compiler for debugging purpose.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. def factorial(num):
  2. if num == 0:
  3. return 1
  4. else:
  5. return num * factorial(num-1)
  6. num=int(input("Input a number to compute the factiorial : "))
  7. print(factorial(num))

Result

python language techstudy.org

     





Related Topics




Popular Posts