#ex(1) 7,13,19,25....
common_diff=19-13
print 6
#ex(2) 6,4,2,0,-2
common_diff=2-4
print -2
#ex(1) in the series 7,10,13,.... the common difference is 3. 10th trerm is ?
nth_term=('7+(n-1)*3')
term10=7+(10-1)*3
#ex(2) i the series 6,2,-2,-6,....and d=-4
nth_term=('6-(n-1)*4')
term8=6+(8-1)*-4
print term8
#insert 3 A.M's between 4 and 20
#let 4,a,b,c,20 are in A.P. using, l=a+(n-1)*d
d=(20-4)/(5-1);
a=4+d;
b=a+d;
c=b+d;
print("the five terms are 4, ,20",a,b,c)
#sum of A.P of 8 terms is 90.1st term is 6.
# using s=n*{2*a+(n-1)*d}/2
#substituting given values
d=0;
for d in range(0,100):
if(90==8/2*(2*6 + (8-1)*d)):
print d
print 'd=1.5'
import numpy
# using s=n*{2*a+(n-1)*d}/2
a=3;d=3;s=135;
#substituting given values
n=('n');
p='n/2*(6 + (n-1)*3)-135';
#n=numpy.roots(p)
print("\n As root -10 is inadmissible, the solution is n=9")
#ex(1).1,2,4,8,...
commom_ratio=4/2
#ex(2). 1,1/2,1/4,1/8,....
common_ratio=(1./4.)/(1./2.)
#ex(3). 2,-6,18,-54
common_ratio=-6/2
#ex(4). R,R^2,R^3,R^4....
R=('R');
common_ratio='R**2/R'
print 'common_ratio',R
#7th term of the series 3,6,12,....
#in the series r=2, so using the formula
# nth term=a*r^(n-1)
a=3;n=7;#given data
term7=3*(2)**(7-1);
print"\n the seventh term of the series is ",term7
#8th term of the series 2,-6,18,-54,......
#in the series r=-3, so using the formula
# nth term=a*r^(n-1)
a=2;n=8;#given data
term8=2*(-3)**(8-1);
print("\n the eighth term of the series is ",term8)
#5th term of the series.1st term is 100 and common ratio(r) is 0.63
# using the formula
#nth term=a*r^(n-1)
a=100;n=0.63;#given data
print"\n the fifth term of the series is \n"
term5=100*0.63**(5-1)
print term5
#3rd term of G.P is 4.5 and 9th is 16.2
# nth term=a*r^(n-1)
term3=4.5;#given data
#'a*r^(3-1)=4.5 ---equ(1)'
term9=16.2;#given
#'a*r^(9-1)=16.2 ---equ(2)'
print("\n the common ratio is :\n");
r=(16.2/4.5)**(1./6.)#equ(2)/equ(1)
print round(r,3)
#sum of 7 terms of the series 2,3,4,5,....
r=3./2.;a=2.;n=7.;#given
#using the formula
S=a*(r**(n)-1)/(r-1)
print ("substituting the given values ")
print round(S,1)
#sum of 7 terms of the series 4,-8,16,....
r=-8./4.;a=4;n=7;#given
#using the formula
S=a*(r**(n)-1)/(r-1)
#substituting the values
print S
#sum to infinity series 2 + 1/2 + 1/8 + ......
a=2;r=1./4.;#given
#using the formula
S_infinity=a/(1-r)
print round(S_infinity,2)
#sum to infinity series 5 - 1 + 1/5 - ......
a=5;r=-1./5.;#given
#using the formula
S_infinity=a/(1-r)
print round(S_infinity,2)