6: Average

Example number 6.1 Page number 6.5

In [2]:
#importing modules
import math
from __future__ import division

#Variable declaration
m=40;       #number of students in A
a=10;       #average age in A
b=12;       #average age in B
n=30;       #number of students in B

#Calculation
average=((m*a)+(n*b))/(m+n);    #average age of students in both sections

#Result
print "average age of students in both sections is",round(average,2),"years"
average age of students in both sections is 10.86 years

Example number 6.2 Page number 6.5

In [3]:
#importing modules
import math
from __future__ import division

#Variable declaration
m=5;   #number of quantities
n=3;   #number of quantities
a=6;   #average of 5 quantities
b=4;   #average of 3 quantities

#Calculation
average=((m*a)-(n*b))/(m-n);     #average of 2 numbers

#Result
print "average of 2 numbers is",average
average of 2 numbers is 9.0

Example number 6.3 Page number 6.5

In [4]:
#importing modules
import math
from __future__ import division

#Variable declaration
m=30;    #number of pens
n=75;    #number of pencils
p=2;     #average price of pencil
S=510;   #cost of pens and pencils

#Calculation
y=(S-(n*p))/m;    #average price of pen(Rs)

#Result
print "average price of pen is",y,"Rs"
average price of pen is 12.0 Rs

Example number 6.4 Page number 6.5

In [6]:
#importing modules
import math
from __future__ import division

#Variable declaration
aplusb=2*20;    #average age of A and B
bplusc=2*19;    #average age of B and C
cplusa=2*21;    #average age of C and A

#Calculation
aplusbplusc=(aplusb+bplusc+cplusa)/2;
a=aplusbplusc-bplusc;    #age of A(years)
b=aplusbplusc-cplusa;    #age of B(years)
c=aplusbplusc-aplusb;    #age of C(years)

#Result
print "age of A is",a,"years"
print "age of B is",b,"years"
print "age of C is",c,"years"
age of A is 22.0 years
age of B is 18.0 years
age of C is 20.0 years

Example number 6.5 Page number 6.6

In [7]:
#importing modules
import math
from __future__ import division

#Variable declaration
e1=2200;     #average monthly expenditure for 3 months(Rs)
n1=3;     #number of months in 1st case
e2=2550;     #average monthly expenditure for 4 months(Rs)
n2=4;     #number of months in 2nd case
e3=3120;     #average monthly expenditure for 5 months(Rs)
n3=5;     #number of months in 3rd case
s=1260;    #total saving(Rs)

#Calculation
I=(e1*n1)+(e2*n2)+(e3*n3)+s;     #total yearly income(Rs)
average=I/12;     #average monthly income(Rs)

#Result
print "average monthly income is",average,"Rs"
average monthly income is 2805.0 Rs

Example number 6.6 Page number 6.6

In [9]:
#importing modules
import math
from __future__ import division

#Variable declaration
TWT=37;     #average temperature on tuesday, wednesday, thursday(C)
FWT=38;     #average temperature on wednesday, thursday, friday(C)
R=39;      #temperature on friday(C)
n=3;      #number of quantities

#Calculation
T=R-((FWT-TWT)*n);     #temperature of tuesday(C)

#Result
print "temperature of tuesday is",T,"C"
temperature of tuesday is 36 C

Example number 6.7 Page number 6.6

In [10]:
#importing modules
import math
from __future__ import division

#Variable declaration
n=3;      #number of quantities
J=29;     #temperature of june(C)
JJA=31;   #average temperature of june, july august(C)
JAS=30;   #average temperature of july, august, september(C)

#Calculation
S=J+((JAS-JJA)*n);     #temperature of september(C)

#Result
print "temperature of september is",S,"C"
temperature of september is 26 C

Example number 6.8 Page number 6.6

In [11]:
#importing modules
import math
from __future__ import division

#Variable declaration
n1=29;     #number of students in class
n2=30;     #number when teacher is included
w1=48;     #average weight of 29 students(kg)
w=0.5;    #change in average weight of 30 members(kg)

#Calculation
wt=((n2-n1)*w1)+(w*n2);    #weight of teacher(kg)

#Result
print "weight of teacher is",wt,"kg"
weight of teacher is 63.0 kg

Example number 6.9 Page number 6.7

In [12]:
#importing modules
import math
from __future__ import division

#Variable declaration
n1=50;    #number of boys in class
w1=45;    #original average(kg)
n2=49;    #number of boys when one leaves the class
dw=0.1;    #reduction in average weight(kg)

#Calculation
a=(n1-n2)*w1;
b=-dw*n2;
w=a-b;    #weight of boy who left the class(kg)

#Result
print "weight of boy who left the class is",w,"kg"
weight of boy who left the class is 49.9 kg

Example number 6.10 Page number 6.7

In [13]:
#importing modules
import math
from __future__ import division

#Variable declaration
n1=40;    #number of students
na=10;     #number of students newly admitted
a1=15;    #original average(years)
a=0.2;    #change in average(year)

#Calculation
sa=(na*a1)+(a*(n1+na));     #sum of weight(kg)
avga=sa/na;     #average age of 10 new students(years)

#Result
print "average age of 10 new students is",avga,"years"
average age of 10 new students is 16.0 years

Example number 6.11 Page number 6.7

In [14]:
#importing modules
import math
from __future__ import division

#Variable declaration
n1=30;     #number of students
n=20;      #number of students newly admitted
a1=60;     #original average(kg)
a=-2;      #change in average weight(kg)

#Calculation
s=(n*a1)+(a*(n1+n));    #sum of weight(kg)
aw=s/n;    #average weight of 20 students(kg)

#Result
print "average weight of 20 students is",aw,"kg"
average weight of 20 students is 55.0 kg

Example number 6.12 Page number 6.7

In [15]:
#importing modules
import math
from __future__ import division

#Variable declaration
n1=6;    #number of results
a1=49;   #average of 1st six results
a2=52;   #average of last six results
n2=11;   
a3=50;   #average of 11 results

#Calculation
v6=(n1*a1)+(n1*a2)-(n2*a3);    #value of 6th result

#Result
print "value of 6th result is",v6
value of 6th result is 56

Example number 6.13 Page number 6.8

In [18]:
#importing modules
import math
from __future__ import division

#Variable declaration
n1=20;    #number of innings
n2=21;    #number of innings in 2nd case
r2=107;   #number of runs
a2=2;     #change in average(runs)

#Calculation
a1=a2*n2;
A=(r2-a1)/(n2-n1);    
A=A+2;       #average after 21 innings(runs)

#Result
print "average after 21 innings is",A,"runs"
average after 21 innings is 67.0 runs

Example number 6.14 Page number 6.8

In [19]:
#importing modules
import math
from __future__ import division

#Variable declaration
Sa=6;    #number of runs in last 2 innings(runs)
na=2;    #number of innings
deltaA=-2;   #drop in average runs
A1=750;    #number of runs

#Calculation
#from the equation 6=(2*750/N)-(2*N+4) we get a quadratic equation in N 
a=-deltaA;    #coefficient of N**2
b=Sa-(na*deltaA);   #coefficient of N
c=-na*A1;    #constant term
N=((-b)+math.sqrt((b**2)-(4*a*c)))/(2*a);    #number of innings
A=A1/N;     #original average
FA=A-na;    #final average(runs)

#Result
print "final average is",FA,"runs"
final average is 28.0 runs

Example number 6.15 Page number 6.8

In [24]:
#importing modules
import math
from __future__ import division

#Variable declaration
sa=52;    #number of runs
na=3;     #number of wickets
A1=200;   #average of bowler
deltaA=1;   #change in average

#Calculation
#from the equation 52=(3*200/N)+(+1)*(N+3) we get a quadratic equation in N 
a=deltaA;   #coefficient of N**2
b=na-sa;    #coefficient of N
c=na*A1;    #constant term
N1=((-b)+math.sqrt((b**2)-(4*a*c)))/(2*a);    #number of innings
N2=((-b)-math.sqrt((b**2)-(4*a*c)))/(2*a);    #number of innings
NA1=(A1+sa)/(N1+na);    #new average
NA2=(A1+sa)/(N2+na);    #new average
x=NA2-int(NA2);

#Result
print "new average of bowler is",NA1,"or",NA2
new average of bowler is 9.0 or 9.33333333333

Example number 6.16 Page number 6.9

In [25]:
#importing modules
import math
from __future__ import division

#Variable declaration
n=15;    #number of students
da=1.5;  #change in average
wr=40;   #weight of removed student(kg)

#Calculation
wn=wr+(n*da);    #weight of new student(kg)

#Result
print "weight of new student is",wn,"kg"
weight of new student is 62.5 kg

Example number 6.17 Page number 6.9

In [26]:
#importing modules
import math
from __future__ import division

#Variable declaration
n=11;    #number of players
ac=25;   #age of captain(years)
awk=28;  #age of wicket keeper(years)
da=-2;   #change in average(years)

#Calculation
S=(ac+awk)+(n*da);   #sum of age of replacing players(years)
A=S/2;    #average age of 2 players(years)

#Result
print "average age of 2 players is",A,"years"
average age of 2 players is 15.5 years