You are on page 1of 2

import 

numpy as np

import matplotlib.pyplot as plt

import random

N=1000

M=20000

def coin(N):

    

 h=t=0

for i in range(N):

  r=random.choice(["H","T"])

  if (r=="H") :

   h=h+1

  else:

   t=t+1

return h,t

def s(M):

  H,T,T1=[],[],[]

  for i in range (M):

    h1,t1=coin(N)

    H.append(h1)

    T.append(t1)

    T1.append(t1+150)

  return H,T,T1

x,y,z=s(M)

plt.hist(x,50,color="white",ec="k")

plt.hist(z,50,color="white",ec="k")

plt.grid(which='major')

plt.minorticks_on()

plt.grid(which='minor', linestyle='dotted')

plt.show()

print("Probability of head=",np.mean(x)/N)

print("Probability of tail=",np.mean(y)/N)

Probability of head= 0.49982655

Probability of tail= 0.50017345

from IPython.display import set_matplotlib_formats

set_matplotlib_formats('pdf', 'svg')

Colab paid products


-
Cancel contracts here

You might also like