I have made the following piece of code to split N persons into random teams of 2, but in many cases, I get the error: pop index out of range
.
Could someone help me?
from random import seed
from random import randrange
from datetime import datetime
seed(datetime.now())
N = int(input("How many students do you have?:"))
pupils = set()
for number in range(N):
pupils.add(str(input('pupil name:')))
print(pupils)
teams = set()
lista = list(pupils)
for i in range(N//2):#// akerea dieresi
pos1 = randrange(0, len(lista))
pos2 = randrange(0, len(lista))
pupil1 = lista.pop(pos1)
pupil2 = lista.pop(pos2)
team = (pupil1,pupil2)
teams.add(team)
i = 0
for team in teams:
i+=1
print(team + str(i))