Find nth Hermite number | Python 3 program to find nth Hermite number ; Utility function to calculate double factorial of a number ; Function to return nth Hermite number ; If n is even then return 0 ; If n is odd ; Calculate double factorial of ( n - 1 ) and multiply it with 2 ^ ( n / 2 ) ; If n / 2 is odd then nth Hermite number will be negative ; Return nth Hermite number ; Driver Code ; Print nth Hermite number
from math import pow NEW_LINE def doubleFactorial ( n ) : NEW_LINE INDENT fact = 1 NEW_LINE for i in range ( 1 , n + 1 , 2 ) : NEW_LINE INDENT fact = fact * i NEW_LINE DEDENT return fact NEW_LINE DEDENT def hermiteNumber ( n ) : NEW_LINE INDENT if ( n % 2 == 1 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT number = ( ( pow ( 2 , n / 2 ) ) * doubleFactorial ( n - 1 ) ) NEW_LINE if ( ( n / 2 ) % 2 == 1 ) : NEW_LINE INDENT number = number * - 1 NEW_LINE DEDENT return number NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 6 NEW_LINE print ( int ( hermiteNumber ( n ) ) ) NEW_LINE DEDENT