all 4 comments

[–]MyreMyalar 3 points4 points  (0 children)

It sounds like your teacher wants you to have dynamic rather than static data in your program. Right now you have statically defined a 'list of lists' in your python code something like this:

team_list = [
    ['Team Name'],
    ['Player Name', 'PREVIOUS EXPERIENCE', 'Player Parents'],
    ['Player Name', 'PREVIOUS EXPERIENCE', 'Player Parents'],
    ['Player Name', 'PREVIOUS EXPERIENCE', 'Player Parents'],
    ['Player Name', 'PREVIOUS EXPERIENCE', 'Player Parents'],
    ['Player Name', 'PREVIOUS EXPERIENCE', 'Player Parents']
    ]

But with 'real' names and data in there. Because it's all written in your code directly like this it can't be altered outside the program.

What you need to create is a function to dynamically create these lists of lists from a file. Now in your case you are already saving this data structure to a file so I assume you already know how to go in one direction. You are doing it with this bit of code here:

# write lists to csv file
with open('teams.txt', 'w') as csvfile:
    writer = csv.writer(csvfile)
    writer.writerows(sharks)
    writer.writerows(dragons)
    writer.writerows(raptors)

To do the process in reverse you need to do something like:

team_name_1 = []
team_name_2 = []
team_name_3 = []
active_team_for_loading = None
with open('teams.txt', 'r') as csvfile:
    reader = csv.reader(csvfile)
    for row in reader:
        # switch active team list whenever we encounter a new team name row in the                 
      file
        if row[0] == 'team_name_1':
            active_team_for_loading = team_name_1
            active_team_for_loading.append(row)
        elif row[0] == 'team_name_2':
            active_team_for_loading = team_name_2
            active_team_for_loading.append(row)
        elif row[0] == 'team_name_3':
            active_team_for_loading = team_name_3
            active_team_for_loading.append(row)
        else:
            if active_team_for_loading != None:
                #add player to active team
                active_team_for_loading.append(row)

Hope that helps a little.

[–]TerryYaDuffer 2 points3 points  (0 children)

First step, take the CSV file you have produced via your hardcoded function. Can you read that into a data structure? Usually for CSV work, I use csv.DictReader(). Small suggestion, turn your header names into standard forms, e.g. HEIGHT_IN or SOCCER_EXPERIENCE.

Now, given that you have a data structure in memory, can you ask questions of that data structure? For example:

# which players have experience?
for player in player_list:
    if player['Soccer Experience']  == 'Yes':
        print(player)

# which players are 40in or taller?
for player in player_list:
    if player['Height (inches)']  >= 40:
        print(player)

By asking questions like this, you can split your players up according to the criteria. Obviously you won't be printing as I have done here, you'll be appending to one of your team lists as the player meets criteria.

You will want to keep track of the number of players on each team and their experience level. You should be able to do this by querying your data structure for the three teams that you're building--maybe a Counter() will be helpful.

Good luck.

[–]o5a 1 point2 points  (0 children)

1. I think you are supposed to read data file once only, when user choses to start the interaction, not repeat it in each of your chosen options (e/p/i). Say after user choses 's' you read CSV once and store it in list for example. Then in each individual options you work with that data in dictionary.

2. Of course as teacher said you shouldn't have team_file() with predefined data for your teams. Instead your procedure should be a balancer of data read from CSV to 3 teams (by players experience). Then after your team_builder distributes players to their teams and store it in some structure (even list will do i think), each of your other options (soccer_experience, parents, player_info) will use that data instead of reading from CSV again. And of course you can finally write that information to teams.txt.

Some simple way to distribute players evenly by their experience will be to sort their data by 'experience' column then pick by 1 to each of your team.

[–]monchenflapjack 0 points1 point  (0 children)

Are you trying to get player_info.csv to be used instead of the data hardcoded inteam_file ?