导入随机但在尝试使用random.choices时获取TypeError

时间:2018-05-10 01:33:53

标签: python

import random

Events_List = [0, 1, 2, 3, 4, 5, 6]
Probability_Distribution = [16.666, 16.666, 16.666, 16.666, 16.666, 16.666, 
                            2 * 10^(-5)]
Random_Choices = random.choices(Events_List, 1, Probability_Distribution)
print("Random_Choices:", Random_Choices)

错误:

TypeError: choices() takes from 2 to 3 positional arguments but 4 were given'

编辑:TypError而不是属性错误

1 个答案:

答案 0 :(得分:0)

解决方案:

import random

Events_List = [0, 1, 2, 3, 4, 5, 6]
Probability_Distribution = [16.666, 16.666, 16.666, 16.666, 16.666, 16.666,
                      2 * 10^(-5)]
Random_Choices = random.choices(Events_List, Probability_Distribution, k = 1)
print("Random_Choices:", Random_Choices)

您所拥有的参数未正确切换。