Pentanacci Numbers | Function to print Nth Pentanacci number ; Initialize first five numbers to base cases ; declare a current variable ; Loop to add previous five numbers for each number starting from 5 and then assign first , second , third , fourth to second , third , fourth and curr to fifth respectively ; Driver code
def printpenta ( n ) : NEW_LINE INDENT if ( n < 0 ) : NEW_LINE INDENT return NEW_LINE DEDENT first = 0 NEW_LINE second = 0 NEW_LINE third = 0 NEW_LINE fourth = 0 NEW_LINE fifth = 1 NEW_LINE curr = 0 NEW_LINE if ( n == 0 or n == 1 or \ n == 2 or n == 3 ) : NEW_LINE INDENT print ( first ) NEW_LINE DEDENT elif ( n == 5 ) : NEW_LINE INDENT print ( fifth ) NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( 5 , n ) : NEW_LINE INDENT curr = first + second + third + fourth + fifth NEW_LINE first = second NEW_LINE second = third NEW_LINE third = fourth NEW_LINE fourth = fifth NEW_LINE fifth = curr NEW_LINE DEDENT DEDENT print ( curr ) NEW_LINE DEDENT n = 10 NEW_LINE printpenta ( n ) NEW_LINE