{"id":16125,"date":"2021-08-12T09:36:58","date_gmt":"2021-08-12T04:06:58","guid":{"rendered":"https:\/\/python-programs.com\/?p=16125"},"modified":"2021-11-22T18:38:26","modified_gmt":"2021-11-22T13:08:26","slug":"python-program-to-find-sum-of-geometric-progression-series","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-sum-of-geometric-progression-series\/","title":{"rendered":"Python Program to Find Sum of Geometric Progression Series"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Repeat String N times with Separator<\/a> A geometric progression series is one in which any two consecutive terms have the same ratio. As a result, we can find the subsequent term by multiplying the common ratio by the previous term.<\/p>\n This is how the series looks:\u00a0 \u00a0a, ar, ar2<\/sup>, ar3<\/sup>, ar4<\/sup>, . . . . .<\/b><\/p>\n where common ratio(r)=2nd term\/1st term (T2\/T1) or (T3\/T2)<\/p>\n Standard Formula to find the sum of series in G.P = \u00a0a(1 \u2013 rn<\/sup>)\/(1 \u2013 r)<\/strong><\/p>\n Given First term(a), common ratio(r), Nth term(total number of terms ) in Series, The task is to find Sum of the Geometric Progression Series.<\/p>\n Example: 2,6,18,54,162,486,1458,. . . . . . . .<\/p>\n Here a=2 , r=6\/2 =3 , let n=10<\/p>\n Formula to find Nth term =\u00a0arn<\/sup>–<\/sup>1\u00a0\u00a0<\/sup><\/b><\/p>\n = 39366<\/p>\n sum of series = a(1 \u2013 rn<\/sup>)\/(1 \u2013 r) <\/strong>=59048<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example 2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to find the Sum of the Geometric Progression Series.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n <\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n In the previous article, we have discussed Python Program to Repeat String N times with Separator Geometric progression series A geometric progression series is one in which any two consecutive terms have the same ratio. As a result, we can find the subsequent term by multiplying the common ratio by the previous term. This is …<\/p>\n
\nGeometric progression series<\/strong><\/p>\nGiven Total number of terms=4\r\nGiven First Term = 3\r\nGiven common ratio = 3<\/pre>\n
The sum of the given geometric progression series = 120<\/pre>\n
Given Total number of terms=6\r\nGiven First Term = 4 \r\nGiven common ratio = 5<\/pre>\n
The sum of the given geometric progression series = 15624<\/pre>\n
Program to Find Sum of Geometric Progression Series<\/h2>\n
\n
Method #1: Using Mathematical Formula (Static Input)<\/h3>\n
\n
# Import math module using import keyword.\r\nimport math\r\n# Give the Total number of terms as static input and store it in a variable.\r\ntot_trms = 10\r\n# Give the first term as static input and store it in a variable.\r\nfst_trm = 2\r\n# Give the Common Ratio as static input and store it in a variable.\r\ncommn_diff = 3\r\n# Calculate the given Sum of Geometric Progression Series by using standard mathematical formula\r\n# a(1 \u2013 r**n)\/(1 \u2013 r) and store it in a variable.\r\nsum_geoprog = (fst_trm*(1-(commn_diff)**tot_trms))\/\/(1-commn_diff)\r\n# Print the sum of Geometric Progression series .\r\nprint(\"The sum of the given geometric progression series = \", sum_geoprog)\r\n<\/pre>\n
The sum of the given geometric progression series = 59048<\/pre>\n
Method #2: Using Mathematical Formula (User Input)<\/h3>\n
\n
#Import math module using the import keyword.\r\nimport math\r\n#Give the Total number of terms as User input using\u00a0the\u00a0int(input())\u00a0function\u00a0and store it in a variable.\r\ntot_trms = int(input(\"Given Total number of terms =\"))\r\n#Give the first term as User input using the int(input()) function and store it in another variable.\r\nfst_trm = int(input(\"Given First Term = \"))\r\n#Give the Common Ratio as User input using\u00a0the\u00a0int(input())\u00a0function\u00a0 and store it in another variable.\r\ncommn_diff = int(input(\"Given common ratio = \"))\r\n#Calculate the Sum of Geometric Progression Series by using standard mathematical formula \r\n#a(1 \u2013 r**n)\/(1 \u2013 r) and store it in a variable.\r\nsum_geoprog = (fst_trm*(1-(commn_diff)**tot_trms))\/\/(1-commn_diff)\r\n#Print the sum of Geometric Progression series .\r\nprint(\"The sum of the given geometric progression series = \", sum_geoprog)\r\n\r\n<\/pre>\n
Given Total number of terms =6\r\nGiven First Term = 4\r\nGiven common ratio = 5\r\nThe sum of the given geometric progression series = 15624<\/pre>\n
\n