vendredi 5 février 2021

How to have my program list every item off of a list randomly and only once

I'm trying to have a function that uses the random import to randomly select a value from the list [0, 1, 2, 3, 4, 5, 6, 7, 8], print that value, then repeat itself until all the numbers are selected. The problem I'm having is then making sure when it repeats itself it won't choose that number again. What I've tried is:

def ListArranger():
    randomPick = random.choices(list)
    if len(list) > 0:
        if list[randomPick] != " ":
            print(list[randomPick])
            list[randomPick] = " "
            ListArranger()
        else:
            ListArranger()

I run into the problem that says list indices must be integers or slices, not list. I'm assuming it's having a problem because I'm trying to set the list value to a string, but I can't figure out how to work around this




Aucun commentaire:

Enregistrer un commentaire