Open In App

Python | sympy.factorial2() method

Last Updated : 14 Jul, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
With the help of sympy.factorial2() method, we can find the Double factorial. Double factorial of a number is given by -
n!! = \begin{cases} 1 & n = 0 \\ n(n-2)(n-4) \cdots 1 & n\ \text{positive odd} \\ n(n-2)(n-4) \cdots 2 & n\ \text{positive even} \\ (n+2)!!/(n+2) & n\ \text{negative odd} \end{cases}
Syntax: factorial2(n) Parameter: n - It denotes the number whose double factorial is to be calculated. Returns: Returns the double factorial of number, i. e., n.
Example #1: Python3
# import sympy 
from sympy import * 

n = 10
print("Value of n = {}".format(n))
 
# Use sympy.factorial2() method 
factorial2_n = factorial2(n)  
    
print("Double factorial of n : {}".format(factorial2_n))  
Output:
Value of n = 10
Double factorial of n : 3840
Example #2: Python3
# import sympy 
from sympy import * 

n = -3
print("Value of n = {}".format(n))
 
# Use sympy.factorial2() method 
factorial2_n = factorial2(n)  
    
print("Double factorial of n : {}".format(factorial2_n))  
Output:
Value of n = -3
Double factorial of n : -1

Next Article
Article Tags :
Practice Tags :

Similar Reads