print "From the principle of counting, the required no. of ways are 12∗11∗10∗9= "
print 12*11*10*9
import math
print "no. of permutations=9!/(2!∗2!∗2!)"
print math.factorial(9)/(math.factorial(2)*math.factorial(2)*math.factorial(2))
import math
print "no. of permutations=9!/(2!∗2!∗3!*3!)"
print math.factorial(9)/(math.factorial(2)*math.factorial(2)*math.factorial(3)*math.factorial(3))
import math
def C(a,b):
x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))
return x
print "no. of committees=C(6,3)∗C(5,2)=’"
print C(6,3)*C(5,2)
import math
def C(a,b):
x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))
return x
print "no. of committees=C(4,1)∗C(5,2)=’"
print C(4,1)*C(5,2)
import math
def C(a,b):
x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))
return x
print "no. of committees=C(6,3)∗C(4,2)=’"
print C(6,3)*C(4,2)
import math
print "The probability of getting a four is 1/6= ",1./6
import math
print "The probability of getting an even no. 1/2= ",1./2
import math
print "The probability of 53 Sundays is 2/7= ",2./7
import math
print "The five digits can be arranged in 5! ways = ",math.factorial(5)
print "Of which 4! will begin with 0 = ",math.factorial(4)
print "So, total no. of five digit numbers = 5!−4! = ",math.factorial(5)-math.factorial(4)
print "The numbers ending in 04, 12, 20, 24, 32, 40 will be divisible by 4 "
print "numbers ending in 04 = 3! = ",math.factorial(3)
print "numbers ending in 12 = 3!−2! = ",math.factorial(3)-math.factorial(2)
print "numbers ending in 20 = 3! = ",math.factorial(3)
print "numbers ending in 24 = 3!−2! = ",math.factorial(3)-math.factorial(2)
print "numbers ending in 32 = 3!−2! = ",math.factorial(3)-math.factorial(2)
print "numbers ending in 40 = 3! = ",math.factorial(3)
print "So, total no. of favourable ways = 6+4+6+4+4+6 = ",6+4+6+4+4+6
print "probability = 30/96 = ",30./96
import math
def C(a,b):
x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))
return x
print "Total no. of possible cases = C(40,4) = ",C(40,4)
print "Favourable outcomes = C(24,2)∗C(15,1) = ",C(24,2)*C(15,1)
print "Probability = ",float(C(24,2)*C(15,1))/C(40,4)
import math
def C(a,b):
x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))
return x
print "Total no. of possible cases = C(15,8) = ",C(15,8)
print "Favourable outcomes = C(5,2)∗C(10,6) = ",C(5,2)*C(10,6)
print "Probability = ",float(C(5,2)*C(10,6))/C(15,8)
import math
def C(a,b):
x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))
return x
print "Total no. of possible cases = C(9,3) = ",C(9,3)
print "Favourable outcomes = C(2,1)∗C(3,1)*C(4,1) = ",C(2,1)*C(3,1)*C(4,1)
print "Probability = ",float(C(2,1)*C(3,1)*C(4,1))/C(9,3)
import math
def C(a,b):
x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))
return x
print "Total no. of possible cases = C(9,3) = ",C(9,3)
print "Favourable outcomes = C(2,2)∗C(7,1)+C(3,2)∗C(6,1)+C(4,2)∗C(5,1) = ",C(2,2)*C(7,1)+C(3,2)*C(6,1)+C(4,2)*C(5,1)
print "Probability = ",float(C(2,2)*C(7,1)+C(3,2)*C(6,1)+C(4,2)*C(5,1))/C(9,3)
import math
def C(a,b):
x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))
return x
print "Total no. of possible cases = C(9,3) = ",C(9,3)
print "Favourable outcomes = C(3,3)+C(4,3) = ",C(3,3)+C(4,3)
print "Probability = ",5./84
print "Probability of drawing an ace or spade or both from pack of 52 cards = 4/52+13/52−1/52= ",4+13-1/52
print "Probability of first card being a king = 4/52 = ",4./52
print "Probability of second card being a queen = 4/52 = ",4./52
print "Probability of drawing both cards in succession = 4/52∗4/52= ",(4./52)*(4./52)
print "Probability of getting 7 in first toss and not getting it in second toss = 1/6∗5/6 = ",(1./6)*(5./6)
print "Probability of not getting 7 in first toss and getting it in second toss = 5/6∗1/6 = ",(5./6)*(1./6)
print "Required probability = 1/6∗5/6+5/6∗1/6 = ",((1./6)*(5./6))+((5./6)*(1./6))
print "Probability of not getting 7 in either toss = 5/6∗5/6 = ",(5./6)*(5./6)
print "Probability of getting 7 at least once = 1−5/6∗5/6 = ",1-(5./6)*(5./6)
print "Probability of getting 7 twice = 1/6∗1/6 = ",(1./6)*(1./6)
print "Probability of engineering subject being choosen = (1/3∗3/8)+(2/3∗5/8) = ",((1./3)*(3./8)) +((2./3)*(5./8))
print "Probability of white ball being choosen = 2/6∗6/13+4/6∗5/13 = ",((2./6)*(6./13))+((4./6)*(5./13))
print "Chances of winning of A=1/2+(1/2)ˆ2∗(1/2)+(1/2)ˆ4∗(1/2)+(1/2)ˆ6∗(1/2)+..= ",(1./2)/(1-(1./2)**2)
print "Chances of winning of B=1−chances of winning of A = ",1-(2/3)
import math
def C(a,b):
x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))
return x
print "Total no. of possible outcomes = C(10,2) = ",C(10,2)
print "Favourable outcomes = 5*5 = ",5*5
print "P = ",25./45
print "Total no. of possible outcomes = 10*10 = ",10*10
print "Favourable outcomes = 5*5+5*5 = ",5*5+5*5
print "P = ",50./100
A = 1./4
B = 1./3
AorB = 1./2
AandB = A+B-AorB
print "Probability of A/B = AandB/B = ",AandB/B
print "Probability of B/A = AandB/A = ",AandB/A
print "Probability of AandBnot = A−AandB = ",A-AandB
print "Probability of A/Bnot = AandBnot/Bnot = ",(1./6)/(1-1./3)
print "Probability of A hitting target = 3/5"
print "Probability of B hitting target = 2/5"
print "Probability of C hitting target = 3/4"
print "Probability that two shots hit = 3/5∗2/5∗(1−3/4)+2/5∗3/4∗(1−3/5)+3/4∗3/5∗(1−2/5) = "
print (3./5)*(2./5)*(1-3./4)+(2./5)*(3./4)*(1-3./5)+(3./4)*(3./5)*(1-2./5)
print "Probability of problem not getting solved = 1/2∗2/3∗3/4 = ",(1./2)*(2./3)*(3./4)
print "Probability of problem getting solved = 1−(1/2∗2/3∗3/4) = ",1-((1./2)*(2./3)*(3./4))
import sympy
print "Total frequency=integrate(f,x,0,2) ="
n = sympy.integrate('x**3',('x',0,1))+sympy.integrate('(2-x)**3',('x',1,2))
print "u1 about origin = ",
u1 = (1/n)*(sympy.integrate('(x)*(x**3)',('x',0,1))+sympy.integrate('(x)*((2-x)**3)',('x',1,2)))
print u1
print "u2 about origin = ",
u2 = (1/n)*(sympy.integrate('(x**2)*(x**3)',('x',0,1))+sympy.integrate('(x**2)*((2-x)**3)',('x',1,2)))
print u2
print "Standard deviation = (u2−u1ˆ2)ˆ0.5= ",(u2-u1**2)**0.5
print "Mean deviation about the mean = (1/n)∗(integrate(|x−1|∗(xˆ3),x,0,1)+integrate(|x−1|∗((2−x)ˆ3),x,1,2))"
print (1/n)*(sympy.integrate('(1-x)*(x**3)',('x',0,1))+sympy.integrate('(x-1)*((2-x)**3)',('x',1,2)))
print "Probability = (0.45∗0.03)/(0.45∗0.03+0.25∗0.05+0.3∗0.04 = ",(0.45*0.03)/(0.45*0.03+0.25*0.05+0.3*0.04)
print "Probability = (1/3∗2/6∗3/5)/(1/3∗2/6∗3/5+1/3∗1/6∗2/5+1/3∗3/6∗1/5) = ",
print ((1./3)*(2./6)*(3./5))/((1./3)*(2./6)*(3./5))+((1./3)*(1./6)*(2./5))+((1./3)*(3./6)*(1./5))
import numpy
print "Probability of no success = 8/27 "
print "Probability of a success = 1/3 "
print "Probability of one success = 4/9"
print "Probability of two success = 2/9"
print "Probability of three success = 2/9"
A = numpy.array([[0,1,2,3],[8./27,4./9,2./9,1./27]])
print "mean=sum of i∗pi = ",
print A[0,0]*A[1,0]+A[0,1]*A[1,1]+A[0,3]*A[1,3]+A[0,2]*A[1,2]
print "sum of i∗piˆ2 = ",
print A[0,0]**2*A[1,0]+A[0,1]**2*A[1,1]+A[0,3]**2*A[1,3]+A[0,2]**2*A[1,2]
print "variance = (sum of i∗piˆ2)−1= ",
print A[0,0]**2*A[1,0]+A[0,1]**2*A[1,1]+A[0,3]**2*A[1,3]+A[0,2]**2*A[1,2]-1
import sympy,numpy
k = sympy.Symbol('k')
A =numpy.array([[0,1,2,3,4,5,6],[k,3*k,5*k,7*k,9*k,11*k,13*k]])
print "Sumof all pi = 1 "
print "Hence ,"
k = 1./49
print "p(x<4) = ",
a = A[1,0]+A[1,1]+A[1,3]+A[1,2]
print a.evalf()
print "p(x>=5) = ",
b = A[1,5]+A[1,6]
print b.evalf()
print "p(3<x<=6) = ",
c = A[1,4]+A[1,5]+A[1,6]
print c.evalf()
print "p(x<=2) = ",
e = A[1,0]+A[1,1]+A[1,2]
print e.evalf()
import sympy,numpy,math
k = sympy.Symbol('k')
A =numpy.array([[0,1,2,3,4,5,6,7],[0,k,2*k,2*k,3*k,k**2,2*k**2,7*k**2+ k]])
print "Sum of all pi = 1"
print "Hence,"
k = 1./10
print "p(x<6) = ",
a = A[1,0]+A[1,1]+A[1,3]+A[1,2]+ A[1,3]+A[1,4]+A[1,6]
print a.evalf()
print "p(x>=6) = ",
b = A[1,6]+A[1,7]
print b.evalf()
print "p(3<x<5) = ",
c = A[1,1]+A[1,2]+A[1,3]+A[1,4]
print c.evalf()
import sympy,numpy,math
y = sympy.Symbol('y')
f = math.e**(-y)
print "Clearly, f>0 for every x in (1,2) and integrate(f,x,0,numpy.inf)= ",
print sympy.integrate(math.e**(-y),('y',0,sympy.oo))
print "Required probability=p(1<=x<=2)= integrate(f,x,1,2) = ",
print sympy.integrate(math.e**(-y),('y',1,2))
print "Cumulative probability function f(2)=integrate(f,x,−%inf,2) = ",
print sympy.integrate(math.e**(-y),('y',0,2))
import sympy
k = sympy.Symbol('k')
print "Total probability = integrate(f,x,0,6)="
p = sympy.integrate('k*x',('x',0,2))
q = sympy.integrate('2*k',('x',2,4))
r = sympy.integrate('-k*x+6*k',('x',4,6))
print p
print q
print r
import numpy
A = numpy.array([[-3.,6.,9.],[1./6,1./2,1./3]])
print "First row of A displays the value of x"
print "The second row of x displays the probability of corresponding to x"
print "E(x) = ",
c = A[0,0]*A[1,0]+A[0,1]*A[1,1]+A[0,2]*A[1,2]
print c
print "E(x)ˆ2 = ",
b = A[0,0]**2*A[1,0]+A[0,1]**2*A[1,1]+A[0,2]**2*A[1,2]
print b
print "E(2∗x+1)^2=E(4∗xˆ2+4∗x+1) = ",4*b+4*c+1
import sympy
print "Total frequency=integrate(f,x,0,2)= "
n = sympy.integrate('x**3',('x',0,1))+sympy.integrate('(2-x)**3',('x',1,2))
print "u1 about origin = "
u1 = (1/n)*(sympy.integrate('(x)*(x**3)',('x',0,1))+sympy.integrate('(x)*((2-x)**3)',('x',1,2)))
print "u2 about origin = "
u2 = (1/n)*(sympy.integrate('(x**2)*(x**3)',('x',0,1))+sympy.integrate('(x**2)*((2-x)**3)',('x',1,2)))
print "standard deviation = (u2−u1ˆ2)ˆ0.5 = ",(u2-u1**2)**0.5
print "Mean deviation about the mean = (1/n)∗(integrate|x−1|∗(xˆ3),x,0,1)+integrate(|x−1|∗((2−x)ˆ3),x,1,2))"
print (1/n)*(sympy.integrate('(1-x)*(x**3)',('x',0,1))+sympy.integrate('(x-1)*((2-x)**3)',('x',1,2)))
import math
def C(a,b):
x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))
return x
print "Probability that exactly two will be defective = C(12,2)∗(0.1)ˆ2∗(0.9)ˆ10 = ",C(12,2)*(0.1)**2*(0.9)**10
print "Probability that at least two will be defective = 1−(C(12,0)∗(0.9)ˆ12+C(12,1)∗(0.1)∗(0.9)ˆ11) = ",
print 1-(C(12,0)*(0.9)**12+C(12,1)*(0.1)*(0.9)**11)
print "The probability that none will be defective = C(12,12)∗(0.9)ˆ12 = ",C(12,12)*(0.9)**12
import math
def C(a,b):
x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))
return x
print "Probability of 8 heads and 4 tail sin 12 trials = p(8) = C(12,8)∗(1/2)ˆ8∗(1/2)ˆ4= ",C(12.,8.)*(1./2)**8*(1./2)**4
print "The expected no. of such cases in 256 sets = 256∗p(8) = ",256*(495./4096)
import math
def C(a,b):
x = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))
return x
print "Probability of a defective part = 2/20 =0.1 "
print "Probability of a non defective part = 0.9 "
print "Probabaility of atleast three defectives in a sample = ",
print 1-(C(20.,0.)*(0.9)**20+C(20.,1.)*(0.1)*(0.9)**19+C(20.,2.)*(0.1)**2*(0.9)**18)
print "No. of sample shaving three defective parts = 1000∗0.323 = ",1000*0.323