# File: nfact.py
# Program to compute n!
#
# Matt Bishop, ECS 10, Spring 2014
#
# compute n!
# assumes n is a non-negative integer
#
def fact(n):
# base case: 0! = 1 (by definition)
if n == 0:
return 1
# recursion: n! = n * (n-1)!
return n * fact(n-1)
#
# the main routine
#
def main():
# input number
try:
n = int(input("Factorial: "))
except:
print("Need an integer")
return
# it better be non-negative!
if n < 0:
print("Need a non-negative integer")
return
# compute n! and announce it
print("%d! =" % n, fact(n))
#
# and away we go!
#
main()