Advertisement
immanual1

factorial.py

Jan 13th, 2025
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. def factorial(n):
  2.  
  3.     if n < 0:
  4.         return "Factorial is not defined for negative numbers."
  5.     elif n == 0:
  6.         return 1
  7.     else:
  8.         fact = 1
  9.         for i in range(1, n + 1):
  10.             fact *= i
  11.         return fact
  12.  
  13. num = int(input("Enter a non-negative integer: "))
  14.  
  15. result = factorial(num)
  16. print("The factorial of", num, "is", result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement