Hello I hope you can help me,
I'm trying to make an algorithm that takes a txt file with a list of names, reorder them randomly and assign them to teams.
It works, the only issue I have is that for some reason it adds an extra space in all rows of the list, except the first element. It is not the txt file, the list is fine there.
for example, I want an output like this:
team 1
dude1
dude2
team 2
dude3
dude4
Instead it does this:
team 1
dude1
dude2
team 2
dude3
dude4
so team 1 does it without the space but everything else has a space at the beggining.
Here's the code:
import random
raw_list = open("list.txt","r")
people_list = []
for line in raw_list.readlines():
people_list.append(line)
raw_list.close()
team_list = []
team_num = int(input("enter the number of teams you want "))
len_people = int(len(people_list))
teams = len_people / team_num
len_people=int(len_people+team_num)
j = 1
i = 1
for n in range(len_people):
if i == 1:
if j>team_num:
popper = random.randint(0, (len(people_list)) - 1)
team_list.append(people_list.pop(popper))
else:
team_list.append(f"Team {j}\n")
i = i + 1
elif i < teams:
i=i+1
popper = random.randint(0, (len(people_list)) - 1)
team_list.append(people_list.pop(popper))
else:
i = 1
j = j + 1
popper = random.randint(0, (len(people_list)) - 1)
team_list.append(people_list.pop(popper))
print (*team_list)
thanks