def factorial(n):
"""
This function calculates the factorial of a non-negative integer.
Args:
n: The non-negative integer for which to calculate the factorial.
Returns:
The factorial of n, or 1 if n is 0.
Raises ValueError if n is negative.
"""
if n < 0:
raise ValueError("Factorial is not defined for negative numbers")
elif n == 0:
return 1
else:
result = 1
for i in range(1, n + 1):
result *= i
return result
# Example usage:
number = 5
fact = factorial(number)
print(f"The factorial of {number} is {fact}")
ZGVmIGZhY3RvcmlhbChuKToKICAiIiIKICBUaGlzIGZ1bmN0aW9uIGNhbGN1bGF0ZXMgdGhlIGZhY3RvcmlhbCBvZiBhIG5vbi1uZWdhdGl2ZSBpbnRlZ2VyLgoKICBBcmdzOgogICAgbjogVGhlIG5vbi1uZWdhdGl2ZSBpbnRlZ2VyIGZvciB3aGljaCB0byBjYWxjdWxhdGUgdGhlIGZhY3RvcmlhbC4KCiAgUmV0dXJuczoKICAgIFRoZSBmYWN0b3JpYWwgb2Ygbiwgb3IgMSBpZiBuIGlzIDAuCiAgICBSYWlzZXMgVmFsdWVFcnJvciBpZiBuIGlzIG5lZ2F0aXZlLgogICIiIgogIGlmIG4gPCAwOgogICAgcmFpc2UgVmFsdWVFcnJvcigiRmFjdG9yaWFsIGlzIG5vdCBkZWZpbmVkIGZvciBuZWdhdGl2ZSBudW1iZXJzIikKICBlbGlmIG4gPT0gMDoKICAgIHJldHVybiAxCiAgZWxzZToKICAgIHJlc3VsdCA9IDEKICAgIGZvciBpIGluIHJhbmdlKDEsIG4gKyAxKToKICAgICAgcmVzdWx0ICo9IGkKICAgIHJldHVybiByZXN1bHQKCiMgRXhhbXBsZSB1c2FnZToKbnVtYmVyID0gNQpmYWN0ID0gZmFjdG9yaWFsKG51bWJlcikKcHJpbnQoZiJUaGUgZmFjdG9yaWFsIG9mIHtudW1iZXJ9IGlzIHtmYWN0fSIpIA==