In this post, we are going to share a Python Program to find sum of even index term. If you are a python beginner and want to start learning the python programming, then keep your close attention in this tutorial as I am going to share a Python Program to find sum of even index term with the output.
To increase your Python knowledge, practice all Python programs, here is a collection of 100+ Python problems with solutions.
Copy the below python program and execute it with the help of python compiler.
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 | /** * Python Program to find sum of even index term */ import math # Return the sum of even index term def evenSum(n) : # Creates a list containing n+1 lists, # each of n+1 items, all set to 0 C = [[0 for x in range(n + 1)] for y in range(n + 1)] # Calculate value of Binomial Coefficient # in bottom up manner for i in range(0, n + 1): for j in range(0, min(i, n + 1)): # Base Cases if j == 0 or j == i: C[i][j] = 1 # Calculate value using previously # stored values else: C[i][j] = C[i - 1][j - 1] + C[i - 1][j] sum = 0; for i in range(0, n + 1): if n % 2 == 0: sum = sum + C[n][i] return sum print evenSum(4) |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.