You are on page 1of 1

1 a) 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:

# Input of size of sample space is required.

You might also like