I have created a code that takes the user's input and creates 5 teams and writes them to the csv file, the code works but it is less efficient as every time the code runs the user will have to redo all the teams, instead of being able to change one team or add one team at one time, is there any possible solution to this? Thank you in advance.
import csv
def adding_teams():
team_1 = []
for i in range(0,6):
name = str(input("You are now entering the data for Team 1.\nYou will see this 6 times, enter the team's name first then the members, all individually."))
team_1.append(name)
print("\n")
team_2 = []
for i in range(0,6):
name = str(input("You are now entering the data for Team 2.\nYou will see this 6 times, enter the team's name first then the members, all individually."))
team_2.append(name)
print("\n")
team_3 = []
for i in range(0,6):
name = str(input("You are now entering the data for Team 3.\nYou will see this 6 times, enter the team's name first then the members, all individually."))
team_3.append(name)
print("\n")
team_4 = []
for i in range(0,6):
name = str(input("You are now entering the data for Team 4.\nYou will see this 6 times, enter the team's name first then the members, all individually."))
team_4.append(name)
print("\n")
team_5 = []
for i in range(0,6):
name = str(input("You are now entering the data for Team 5.\nYou will see this 6 times, enter the team's name first then the members, all individually."))
team_5.append(name)
print("\n")
header_teams = ['TeamName', 'Member1', 'Memberb2', 'Member3', 'Member4', 'Member5']
teams_data = [
team_1,
team_2,
team_3,
team_4,
team_5]
with open('teams.csv', 'w', newline = '', encoding='UTF8') as f:
writer = csv.writer(f)
#writing the header for the csv file.
writer.writerow(header_teams)
with open('teams.csv', 'a', newline = '', encoding='UTF8') as f:
writer = csv.writer(f)
#writing the data for each team.
writer.writerows(teams_data)
f.close()
adding_teams()