import random
sample_size = int(input("Enter the number of times you want me to roll the die: "))
if (sample_size <=0):
print("Please enter a positive number!")
else:
counter1 = 0
counter2 = 0
final = 0
while (counter1<= sample_size):
dice_value = random.randint(1,6)
if ((dice_value) == 6):
counter1 += 1
else:
counter2 +=1
final = (counter2)/(sample_size) # fixing indention
print("Estimation of the expected number of rolls before pigging out: " + str(final))
这里使用的逻辑正确吗?它将重复滚动一个模具,直到一个模具被轧制,同时跟踪它在一个模具出现之前所用的辊数。当我对高值(500+)运行它时,它的值为0.85
谢谢
按照您的概念,我将创建一个包含每个滚动的列表,然后使用enumerate来计算每个
1
之间的索引数量,并将这些索引作为标记进行相加。在存储a1出现前所用转鼓数总和的变量-OP
样品尺寸500:
一个样本输出:
^{pr2}$另一个示例输出:
相关问题 更多 >
编程相关推荐