I am trying to select a random element from my array.
However, sometimes I am getting an index out of bounds error, even though I accounted for the array starting at 0 by adding 1 to the maximum value of the index.
from random import randint
names = ['Sam', 'Paul', 'Mark', 'Simon', 'Sean', 'Samantha', 'Ellen']
random_name = names[randint(0, len(array)+1)]
print(random_name)
I only get an index out of bounds error sometimes?
Aucun commentaire:
Enregistrer un commentaire