Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def factorial(n):
- if n < 0:
- return "Factorial is not defined for negative numbers."
- elif n == 0:
- return 1
- else:
- fact = 1
- for i in range(1, n + 1):
- fact *= i
- return fact
- num = int(input("Enter a non-negative integer: "))
- result = factorial(num)
- print("The factorial of", num, "is", result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement