vendredi 16 octobre 2020

Generating a random index within the new list

I have a list of ten team (team1, team2, team3, etc.) I need to define a function called order and use the built-in module random to generate a random index within the list that removes the team from the current list and adds it to the new empty list. I repeat the steps until the old list is empty.

This is what I have but it not right. So not sure what I'm doing wrong and how to fix it.

import random
teams = ["team1", "team2", "team3", "team4", "team5", "team6", "team7", "team8", "team9", 
"team10"]
def order ():
    new_order = []
    new_order = random.choice(teams)
    new_order.append(teams.pop())
print(new_order)



Aucun commentaire:

Enregistrer un commentaire