-
Notifications
You must be signed in to change notification settings - Fork 0
/
doublefact.py
41 lines (33 loc) · 767 Bytes
/
doublefact.py
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
37
38
39
40
41
# doublefact.py
# Python 2.7
import scipy.misc as sm
def my_double_fact(n):
#result = 1
#stop = 2 # for even n
#if n % 2 == 0:
# stop = 1 # odd n
#for i in xrange(n, stop-1, -2):
# result *= i
#return result
result = 1
for i in xrange(n, 0, -2):
result *= i
return result
# =====
print "\nBegin double factorial function demo \n"
n = 3
dfact = sm.factorial2(n)
print "Double factorial of " + str(n) + " using misc.factorial2() = "
print str(dfact)
print ""
n = 4
dfact = sm.factorial2(n)
print "Double factorial of " + str(n) + " using misc.factorial2() = "
print str(dfact)
print ""
n = 4
dfact = my_double_fact(n)
print "Double factorial of " + str(n) + " using my_double_fact() = "
print str(dfact)
print ""
print "\nEnd demo \n"