Each of k jars contains m white and n black balls. A ball is randomly chosen from jar 1 and transferred to jar 2, then a ball is randomly chosen from jar 2 and transferred to jar 3, etc. Finally, a ball is randomly chosen from jar k. Show that the probability that the last ball is white is the same as the probability that the first ball is white, i.e. , it is m/(m + n) .

Write a short Python program for problem 22. Provide indented code and comments explaining your solution.

Respuesta :

Answer:

#initial probability of getting a white ball

init_prob_white=15/25

#initial probability of getting a black ball

init_prob_black=10/25

#probability of getting a white ball given

#that we transferred a white ball in previous

#step is 16/26 which we represent by pww

pww=16/26

#probability of getting a white ball given

#that we transferred a black ball in previous

#step is 15/26 which we represent by pwb

pwb=15/26

#similarly

pbb=11/26;

pbw=10/26;

#The below two functions are recursive which calculate

#total probability right from the start

#The formula they use are

# Prob(W_k)=Prob(W_k-1)*Prob(W_k | W_k-1)+

# Prob(B_k-1)*Prob(W_k | B_k-1)

def pw(n):

if n==1:

return init_prob_white;

else:

return (((pww)*pw(n-1))+((pwb)*pb(n-1)))

def pb(n):

if n==1:

return 10/25;

else:

return (((pbb)*pb(n-1))+ ((pbw)*pw(n-1)))

#for k=5

k=5

x=pw(k)

print("After "+str(k)+" transfers probability="+str(x))

Explanation: