mardi 8 décembre 2020

Getting error :IndexError: Cannot choose from an empty sequence. But actually the list is not empty yet

I'm using random.choice for choosing football player but getting error. It stops after few iterations.

class footballist(Person):                            
def choose(self):                                 
    teams = ['A', 'B']                            
    countA = 0                                    
    countB = 0                                    
    for i in range(0, 22):                        
        team = random.choice(teams)               
        if team == 'A':                           
            countA += 1                           
        else:                                     
            countB += 1                           
        name = random.choice(names)               
        names.remove(name)                        
        print(team, name)                         
        print(countA, countB)                     
        if countA or countB == 11:                
            teams.remove(team)                    
        else:                                     
            pass                                  



Aucun commentaire:

Enregistrer un commentaire