human
Print the sequence of size N in which every term is sum of previous K terms | Function to generate the series in the form of array.
Pick a starting point.
Computing the previous sum.
Loop to print the series.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to print the sequence of size N in which every term is sum of previous K terms and the other steps required.
 def sumOfPrevK ( N , K ) :
	arr = [ 0 ] * N ;
	prevsum = 0 ;
	arr [ 0 ] = 1 ;
	for i in range ( N - 1 ) :
		if ( i < K ) :
			arr [ i + 1 ] = arr [ i ] + prevsum ;
			prevsum = arr [ i + 1 ] ;
		else :
			arr [ i + 1 ] = arr [ i ] + prevsum - arr [ i + 1 - K ] ;
			prevsum = arr [ i + 1 ] ;
	for i in range ( N ) :
		print ( arr [ i ] , end = " ▁ " ) ;
if __name__ == ' _ _ main _ _ ' :
	N = 8 ;
	K = 3 ;
	sumOfPrevK ( N , K ) ;