IndexError:列表索引超出范围我该如何解决并使其运行?

时间:2018-10-23 03:37:11

标签: python

enter image description here

我收到IndexError:列表索引超出范围

1 个答案:

答案 0 :(得分:0)

您应该知道的第一件事是,randint(start, end)函数随机生成从startend的数字。因此,在您的情况下,它所生成的数字比列表中具有的索引多。可以,

people = randint(0, len(persons)-1)