dimanche 19 mars 2023

I have a problem with using Random in a for loop

I have this code

self.savage_ite = ["Can't live without it", "out for the night", "Creepin"," My choppa hate niggas", "Rich nigga shit", "Slidin","Umbrella", "rockstar"]

for i in range(6):
            element = random.choice(self.savage_ite)
            self.savage_set.append(element)
            self.savage_ite.remove(element)

And I keep getting this error

  File "c:\Users\Edwin\Desktop\caca.py", line 8, in <module>
    savage = setlist.create_savage_set()
  File "c:\Users\Edwin\Desktop\real.py", line 37, in create_savage_set
    element = random.choice(self.savage_ite)
  File "C:\Users\Edwin\anaconda3\lib\random.py", line 346, in choice
    return seq[self._randbelow(len(seq))]
IndexError: list index out of range

Is the problem with my code or without the random module?




Aucun commentaire:

Enregistrer un commentaire