【发布时间】:2022-01-05 08:44:22
【问题描述】:
问题是:
在 Chuck-a-Luck 游戏中,我们掷三个骰子,每个骰子有六个面,编号为 1 到 6。玩家在一个数字上下注欧元。如果这个数字没有出现,欧元就会丢失。如果该数字出现一次或多次,玩家将赢得与该数字出现次数一样多的欧元。
这款游戏的预期价值是多少?平均支出是多少?
我计算出的值为:
dice1 = 6
dice2 = 6
dice3 = 6
total_posibility = 216 # the total possibilities that three dice can have
not_match_our_number = 5*5*5 = 125 # the outcome will not much our number
dice_1_and_2_match = 1*1*5
dice_1_and_3_match = 1*5*1
dice_2_and_3_match = 5*1*1
total_of_2_dice_match = 15 # total possibilities that two dice outcome will be our number
total_posibility-(1+15+125) = 75 # total possibilities that one dice outcome will be our number
pr_3_match = 1/total_posibility
pr_2_match = 15/total_posibility
pr_1_match = 75/total_posibility
pr_no_match = 125/total_posibility
expected_value = 3*pr_3_match+2*pr_2_match+1*pr_1_match+-1*pr_no_match
expected_value
= -0.07870370370370372
但我正在尝试实现上述问题:
def run_trials(n=1,seed=None, debug=True):
if seed is not None: rnd.seed(seed)
dice_1 = [1,2,3,4,5,6]
dice_2 = [1,2,3,4,5,6]
dice_3 = [1,2,3,4,5,6]
all_possibility = 216
all_die = 1/216
two_die = 15/216
one_die = 75/216
no_die = 125/216
win3 = 0
win2 = 0
win1 = 0
lose = 0
for k in range(n):
if debug: print(f"trials: {k}")
a = rnd.choice(dice_1)
pick_1 = rnd.choice(dice_1 , size = 1, replace = True)
pick_2 = rnd.choice(dice_2 , size = 1, replace = True)
pick_3 = rnd.choice(dice_3 , size = 1, replace = True)
if a == pick_1 == pick_2 == pick_3 :
win3 = 3
if a == pick_1 and pick_2 or a == pick_1 and pick_3 or a == pick_2 and pick_3:
win2 = 2
if a == pick_1 or a == pick_2 or a == pick_3:
win1 = 1
if a != pick_1 or a!= pick_2 or a!= pick_3:
lose = -1
expected = win3*all_die+win2*two_die+win1*one_die+lose*no_die
if debug: print(f" expected value: {expected}")
run_trials(seed = 60, debug = True)
运行:
trials: 0
expected value: -0.5787037037037037
但是,我得到了错误的答案。我可以尝试解决什么问题?
【问题讨论】:
-
也尝试打印出
win3、win2、win1和lose的各个值。我认为他们不会像你期望的那样行事。 -
@aschepler 你是对的,我得到了 0,0,0 和 -1。这是因为
=还是我使用if作为错误选项?谢谢
标签: python probability