Skip to content

Commit

Permalink
Merge pull request #1 from gulshanjakhon/my-new-branch-1
Browse files Browse the repository at this point in the history
Sum and product of n terms of GP series in python
  • Loading branch information
gulshanjakhon authored Oct 10, 2021
2 parents 6d1f9ca + b3d3a45 commit 99fb84f
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def sumOfGP( a, r, n) :
return ((a*(1-(r**n)))/(1-r))
#Return sum of G.P

def productOfGP(a, r, n):
product = 1;
for i in range(0, n):
product = product * a;
a = a * r;
return product;
# Return the product of g.p.


# Input first term
a=int(input("Enter 1st Termm : "))
# Input common ratio of G.P.
r=int(input("Enter common ratio : "))
# input number of terms
n=int(input("Enter total no of terms : "))
print('Sum of G.P. : '+str(sumOfGP(a, r, n)))
print('Product of G.P. : '+str(productOfGP(a, r, n)))

0 comments on commit 99fb84f

Please sign in to comment.