【发布时间】:2020-09-02 18:11:37
【问题描述】:
j 在达到 5 时停止计数,尽管我的范围以 11 结束。
为什么会发生,我该如何解决?
存在问题的部分代码:
dice1 = random.randrange(1,7)
def probabilities_sum():
print('\nprobability for 2 dices:')
for j in range(1, 12):
percentage_2 = (count[j] / freq) * 100
procent_2 = str(percentage_2)
print('this is J', j)
print(j + 1, ':', procent_2)
【问题讨论】:
-
什么是
count? -
count 计算 2 个骰子的总和(从 2 到 12)
-
给出你写的代码。没有它就很难解决你的问题
-
count() 方法返回具有指定值的元素的数量,可以是任何类型(字符串、数字、列表、元组等)。要搜索的值。
-
你能显示count()的代码吗?我认为这是问题的根源@Khan
标签: python list indexoutofboundsexception