Unit 08 · lesson
Build a Player Roster Manager
Core path: 35 minutes
Until now, most variables in the course represented one value at a time. This build changes the scale.
You are going to manage multiple records, where each record contains several related fields.
That means the structure itself matters.
Start with the shape of the data
Use a list for the roster:
players = []
Each item in that list will be a dictionary such as:
{
"name": "Nova",
"score": 850,
"rank": "ADVANCED",
"online": True
}
Read that structure from the outside in:
players
↓
list of player records
↓
one dictionary
↓
keys such as name / score / rank / online
A list answers which records are in the collection?
A dictionary answers which labeled fields belong to this record?
Create one player at a time
Write:
def create_player():
name = input("Player name: ")
score = int(input("Score: "))
online_text = input("Online? yes/no: ").lower()
online = online_text == "yes"
rank = determine_rank(score)
return {
"name": name,
"score": score,
"rank": rank,
"online": online,
}
Then collect several players:
player_count = int(input("How many players? "))
for _ in range(player_count):
players.append(create_player())
The list grows one record at a time.
Display the roster
Loop through the collection:
for player in players:
print(f'{player["name"]} | {player["score"]} | {player["rank"]}')
Notice the two access patterns working together:
for player in players → get one dictionary from the list
player["name"] → get one field from that dictionary
Calculate from the collection
Count online players:
online_count = 0
for player in players:
if player["online"]:
online_count += 1
Calculate average score:
total_score = 0
for player in players:
total_score += player["score"]
if len(players) > 0:
average_score = total_score / len(players)
That empty-list check matters. A collection with zero records is still a valid program state, and dividing by zero is not.
Find the highest score without hiding the algorithm
Do this manually first:
highest_score = players[0]["score"]
highest_player = players[0]["name"]
for player in players:
if player["score"] > highest_score:
highest_score = player["score"]
highest_player = player["name"]
Later Python gives you shorter tools for this kind of task. Right now I want the mechanism visible: compare the current record against the best result seen so far, then replace the stored best when needed.
Search by name
Ask for a player name and walk the roster until you find a match.
Track whether the search succeeded so the program can distinguish:
match found
vs.
loop finished with no match
Then print either the player details or Player not found.
Add one field that earns its place
Add a field such as:
team
wins
device
region
But do not add data just to make the dictionary longer.
Build one feature that uses the field. Examples:
- list players on a chosen team;
- show players with more than 10 wins;
- count players by device type.
Data that the program never uses is just clutter.
Success evidence
Your roster manager should demonstrate:
- a list containing multiple dictionaries;
- a function that creates one record;
- append and iteration;
- dictionary field access;
- an online count;
- an average with an empty-list guard;
- a manual highest-score algorithm;
- a search that handles no match; and
- one original field tied to a working feature.
This week is not really about memorizing three data structures. It is about choosing a structure that matches the shape of the problem.