-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfactorial.py
More file actions
36 lines (26 loc) · 845 Bytes
/
factorial.py
File metadata and controls
36 lines (26 loc) · 845 Bytes
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
31
32
33
34
35
36
#!/usr/bin/env python
def factorial(n):
"""
copmutes the factorial of n
param: n -- an integer to copute the factorial of
returns: the factorial of n
"""
f = float(n)
n = int(n)
if n != f:
print "factorial only works for integers:",
return None
if n == 0:
return 1
else:
return n * factorial(n-1)
print "the factorial of 0 is:", factorial(0)
print "the factorial of 1 is:", factorial(1)
print "the factorial of 2 is:", factorial(2)
print "the factorial of 3 is:", factorial(3)
print "the factorial of 4 is:", factorial(4)
#print "the factorial of 983 is:", factorial(983)
#print "the factorial of 984 is:", factorial(984)
#print "the factorial of 4L is:", factorial(4L)
#print "the factorial of 1.5 is:", factorial(1.5)
## checking types: -- is instance