【发布时间】:2022-11-18 08:59:25
【问题描述】:
这就是问题: 模拟掷两个骰子的平均值。 这是我到目前为止的代码:
from random import seed, randint
def simulate():
"""
Roll two dice and return their sum
"""
dice_1 = randint(1,6)
dice_2 = randint(1,6)
sum = dice_1 + dice_2
### Main
seed(0)
total = 0
# Use a for loop that runs for 1000 iterations
for trial in range(1000):
simulate()
接下来的步骤是:
# Call simulate() inside the loop to generate the sum
# of two dice and add it into total
现在,我已经调用了 simulate() 函数,但我对如何将它添加到我拥有的 total 变量中有点困惑。
【问题讨论】:
标签: python montecarlo