玩家在游戏中开宝箱有概率获得装备A和B,开一次宝箱需要100游戏币,每次只能获得一个道具,其中获得装备A的概率5%,获得装备B的概率为15%。请问,玩家在放回随机的条件下获得一套A和B,需要游戏币的期望是多少?请写出计算过程。
def cal_factorial(n):
if n == 0 or n == 1:
return 1
else:
return (n * cal_factorial(n - 1))
n = 1000
num = 0
probablity = 0
sum_probablity = 0
for a in range(2,n+1):
for b in range(1,a):
probablity += cal_factorial(a-1)/(cal_factorial(b)*cal_factorial(a-1-b))\
* (0.05*0.15**b + 0.15*0.05**b) * 0.8**(a-1-b)
sum_probablity += probablity
num += a*probablity
print("第{}次开箱成功的概率是:{}".format(a,probablity))
probablity = 0
print("总计概率:",sum_probablity)
print("开箱成功的期望次数:",num)