Professional Documents
Culture Documents
Coin Toss Expt.
Coin Toss Expt.
CODE:
# Fraction of Head's.
def Heads_fraction(n):
N = range(1,n)
h = 0
H = []
for i in N:
h += random.choice([0,1])
H.append(h/i)
return H
# For plotting
import matplotlib.pyplot as plt
n = eval(input("Enter size of sample space\n=\t"))
x = list(range(1,n))
y = Heads_fraction(n)
plt.title("Coin toss",fontsize="20")
plt.axhline(y[n-2],linestyle="--")
plt.xlabel("Size of sample space")
plt.ylabel("Head's Fraction")
plt.plot(x,y)
plt.show()
OUTPUT: