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: