dimanche 22 juillet 2018

List index out of range using randint

I'm currently playing around with trying to append a random item (using randint) from a list to another list before adding the next item. Well, that's probably a weird way of putting it but I'm not sure how else to describe it - I apologize. So instead, here's my current code in question and the output I desire:

Code:

import random

lineIDPart3 = []
lineIDSpace6 = []
lineIDSpace6Poss = ["4", "0", "C", "8"]
lineIDSpace6Num = random.randint(0, 3)
while len(lineIDPart3) < 34:
    lineIDPart3.append(lineIDSpace6Poss[lineIDSpace6Num])
    if lineIDSpace6Num < 4:
        lineIDSpace6Num += 1
    else:
        lineIDSpace6Num = 0
print(lineIDPart3)

Example of the output I want:

["C", "8", "4", "0", "C", "8"...]

I'm pretty stumped on this one so any and all help is appreciated!




Aucun commentaire:

Enregistrer un commentaire