In [2]:

```
#Varible declaration
n = range(1,51,1)
Prob = 0
for x in n:
Prob = 1./len(n) + Prob
#Results
print 'Probability of picking up any one ball is %3.1f'%Prob
```

In [3]:

```
from fractions import Fraction
#Variable Declaration
n = 52 #Total cards
nheart = 13 #Number of cards with hearts
#Calculations
Pe = Fraction(nheart,n)
#Results
print 'Probability of one (heart)card picked from a std. stack of %d cards is'%n,Pe
```

In [4]:

```
#Variable Declaration
n = 52 #Total cards
#Calculations
TotalM = n*(n-1)*(n-2)*(n-3)*(n-4)
#Results
print 'Total number of Five card arrangment from a deck of 52 cards is %d'%TotalM
```

In [5]:

```
#Variable Declaration
n1 = 2 #Two spin states for 1st electron in orbit 1
n2 = 2 #Two spin states for 2nd electron in orbit 2
#Calculation
M = n1*n1
#Results
print 'Possible spin states for excited state are %2d'%M
```

In [6]:

```
from math import factorial
#Variable Declaration
n = 12 #Total Number of players
j = 5 #Number player those can play match
#Calculation
P = factorial(n)/factorial(n-j)
#Results
print 'Maximum Possible permutations for 5 player to play are %8d'%P
```

In [7]:

```
from math import factorial
#Variable Declaration
n = 52 #Number of cards in std . pack
j = 5 #Number of cards in subset
#Calculation
C = factorial(n)/(factorial(j)*factorial(n-j))
#Results
print 'Maximum Possible 5-card combinations are %8d'%C
```

In [8]:

```
from math import factorial
#Variable Declaration
x = 6 #Number of electrons
n = 2 #Number of states
#Calculation
P = factorial(x)/(factorial(n)*factorial(x-n))
#Results
print 'Total number of quantum states are %3d'%P
```

In [9]:

```
from math import factorial
from fractions import Fraction
#Variable Declaration
n = 50 #Number of separate experiments
j1 = 25 #Number of sucessful expt with heads up
j2 = 10 #Number of sucessful expt with heads up
#Calculation
C25 = factorial(n)/(factorial(j1)*factorial(n-j1))
PE25 = Fraction(1,2)**j1
PEC25 = (1-Fraction(1,2))**(n-j1)
P25 = C25*PE25*PEC25
C10 = factorial(n)/(factorial(j2)*factorial(n-j2))
PE10 = Fraction(1,2)**j2
PEC10 = (1-Fraction(1,2))**(n-j2)
P10 = C10*PE10*PEC10
#Results
print 'Probability of getting 25 head out of 50 tossing is %4.3f'%(float(P25))
print 'Probability of getting 10 head out of 50 tossing is %4.3e'%(float(P10))
```

In [10]:

```
from math import factorial, log
#Variable Declaration
N = [10,50,100] #Valures for N
#Calculations
print ' N ln(N!) ln(N!)sterling Error'
for i in N:
lnN = log(factorial(i))
lnNs = i*log(i)-i
err = abs(lnN-lnNs)
print '%3d %5.2f %5.2f %4.2f'%(i,lnN,lnNs, err)
```

In [11]:

```
from fractions import Fraction
#Variable Declaration
fi = 1 #Probability of receiving any card
n = 52 #Number od Cards
#Calculations
sum = 0
for i in range(52):
sum = sum + fi
Pxi = Fraction(fi,sum)
#Results
print 'Probability of receiving any card', Pxi
```

In [12]:

```
from math import exp
from scipy import integrate
#Variable Declaration
#Calculations
fun = lambda x: exp(-0.05*x)
Pt = 0
for i in range(0,101):
Pt = Pt + fun(i)
Ptot = integrate.quad(fun, 0.0, 100.)
#Results
print 'Sum of Px considering it as discrete function %4.1f'%Pt
print 'Sum of Px considering it as contineous function %4.1f'%Ptot[0]
```

In [13]:

```
from sympy import Symbol
#Variable Declaration
r = Symbol('r') #Radius of inner circle
C = [5,2,0]
#Calculations
A1 = pi*r**2
A2 = pi*(2*r)**2 - A1
A3 = pi*(3*r)**2 - (A1 + A2)
At = A1 + A2 + A3
f1 = A1/At
f2 = A2/At
f3 = A3/At
sf = f1 + f2 + f3
ns = (f1*C[0]+f2*C[1]+f3*C[2])/sf
#Results
print 'A1, A2, A3: ', A1,', ', A2,', ', A3
print 'f1, f2, f3: ', f1,f2,f3
print 'Average payout $', round(float(ns),2)
```