File: factorial

package info (click to toggle)
mathomatic 16.0.5-5.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,192 kB
  • sloc: ansic: 22,029; makefile: 340; sh: 319; python: 96; awk: 39
file content (30 lines) | stat: -rwxr-xr-x 755 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/python3

# This is a Python program to display large factorials and test "fact.py".

from fact import factorial
import sys
import os
import string

def usage():
	print("This program calculates large factorials.")
	print("Requires and tests \"fact.py\".")
	print()
	print("Usage: %s integer_expressions" % os.path.basename(sys.argv[0]))
	print()
	print("The integer expressions should be separated by spaces.")
	print("A factorial is the product of all positive integers <= a given integer.")
	sys.exit(2)

args = sys.argv[1:]
if (args == []):
	usage()
else:
	try:
		num = eval(string.join(args))
		print("factorial(", num, ") =", factorial(num))
	except:
		for arg in args:
			num = eval(arg)
			print("factorial(", num, ") =", factorial(num))