--> Code Repository

Code Repository

/home/morrison/public_html/code/python/sys




Guide to Contents

This page looks at examples from the Python module sys.

Here is factorial.py.

#!/usr/bin/env python3
import sys
def factorial(n):
    return 1 if n == 0 else n*factorial(n - 1)
sys.setrecursionlimit(10003)
n = int(sys.argv[1])
print("%s! = %s" % (n,factorial(int(sys.argv[1]))))

This works for any number up to 10,000.

 $ ./factorial.py 100
 100! = 9332621544394415268169923885626670049071596826438162146859\
 29638952175999932299156089414639761565182862536979208272237582511\
 85210916864000000000000000000000000
 $