forked from mckrd/py_repo_beginner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeometric Progression
More file actions
31 lines (24 loc) · 882 Bytes
/
Copy pathGeometric Progression
File metadata and controls
31 lines (24 loc) · 882 Bytes
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
# Function to generate_AP
def generate_GP(a, r, n):
GP_series = []
for i in range(0,n):
GP_series.append(float(a* pow(r,i)))
return GP_series
print('enter test_cases')
T = int(input())
if T<=25 and 1<=T:
for i in range(1,T+1):
print("enter values for case",i)
print("enter 1st element, ratio , number of terms: ")
a,r,n = map(int, input().split())
if ((int(a)<=20) and (-20<=int(a))) and ((int(r)<=20) and (-20<=int(r))) and ((int(n)<=20) and (-20<=int(n))):
GP_series = generate_GP(a, r, n)
print("GP is -")
print(GP_series)
sum_GP_series =a*((1- pow(r,n))/(1-r))
print("Sum of GP terms is -")
print (sum_GP_series)
else:
print("values out of range")
else:
print("test case out of range")