Introduction
Analysts do not just look at final scores. They break down how a team wins and loses across a season: scoring, pace, efficiency, and patterns that repeat.
In this project, you will build a small program that scans a season-length game log and answers questions like:
- Which games were wins?
- Which wins were also high scoring?
- Which opponents caused trouble?
- What patterns show up across the season?
What we're building
By the end of this project, you will:
- Use conditionals to label wins and losses
- Filter games based on score, result, and pace
- Search and group games to find patterns
- Sort games to find the biggest wins and losses
- Load a CSV file to analyze season-style data
Why this matters
Filtering data is one of the most important skills in analytics. It lets you answer specific questions quickly and gives you evidence to back up an argument.
Part 1: Quick Start
Download the Starter Pack
>button: Download the Starter PackOpen the starter pack in Cursor by going to File > Open Folder and selecting the folder you downloaded from your computer.
You should see a file called team_breakdown.py. Open it, this is where we will be writing our code.
Download the Basketball Season CSV
>button: Download Basketball Season CSVMove the downloaded team_games.csv into the same folder as team_breakdown.py.
Writing the code
Type the code below into team_breakdown.py:
team_name = "Your Team"
team_score = 112
opponent_score = 104
print(f"{team_name} scored {team_score} and allowed {opponent_score}")
if team_score > opponent_score:
print("Result: Win")
else:
print("Result: Loss")
Running the code
Save the file (Cmd + S or Ctrl + S)
Run the code by clicking the "play" icon in the top right of the screen. Or open the terminal (Cmd + ~ or Ctrl + ~) and type python team_breakdown.py.
If everything is working correctly, you should see:
Your Team scored 112 and allowed 104
Result: Win
Nice! You just used a conditional to decide a win or loss.
Part 2: Project Milestones
Milestone 1: Store multiple games in a list
Now we will store multiple games so we can analyze a full stretch of the season. We will include the opponent and whether the game was home or away.
games = [
["Oct 20", "Bears", "Home", 112, 104],
["Oct 23", "Wolves", "Away", 121, 117],
["Oct 26", "Hawks", "Home", 95, 101],
["Oct 29", "Knights", "Away", 124, 108]
]
Each inner list represents [date, opponent, home_away, team_score, opponent_score].
Milestone 2: Label each game as a win or loss
Loop through the list and use a conditional to print the result for each game.
for game in games:
date = game[0]
opponent = game[1]
home_away = game[2]
team_score = game[3]
opponent_score = game[4]
if team_score > opponent_score:
result = "Win"
else:
result = "Loss"
print(f"{date} vs {opponent} ({home_away}): {team_score}-{opponent_score} ({result})")
Expected output:
Oct 20 vs Bears (Home): 112-104 (Win)
Oct 23 vs Wolves (Away): 121-117 (Win)
Oct 26 vs Hawks (Home): 95-101 (Loss)
Oct 29 vs Knights (Away): 124-108 (Win)
Milestone 3: Filter high-scoring, high-pace wins
Pace can be approximated by total points in the game. Let us filter only the games that were wins and also high pace.
high_score = 110
high_pace = 220
for game in games:
team_score = game[3]
opponent_score = game[4]
pace = team_score + opponent_score
efficiency = team_score / opponent_score
if team_score > opponent_score and team_score >= high_score and pace >= high_pace and efficiency >= 1.02:
print(f"High-pace win: {team_score}-{opponent_score} (pace {pace}, eff {efficiency:.2f})")
Expected output:
High-pace win: 121-117 (pace 238, eff 1.03)
High-pace win: 124-108 (pace 232, eff 1.15)
Milestone 4: Load games from a CSV file
Use the team_games.csv you downloaded earlier to analyze a longer stretch of games.
The file looks like this:
date,opponent,home_away,team_score,opponent_score
2025-01-03,Bears,Home,112,104
2025-01-05,Wolves,Away,98,110
2025-01-08,Hawks,Home,121,117
Use this code to load it:
import csv
games_from_file = []
with open("team_games.csv", "r") as file:
reader = csv.DictReader(file)
for row in reader:
games_from_file.append([
row["date"],
row["opponent"],
row["home_away"],
int(row["team_score"]),
int(row["opponent_score"])
])
print("Loaded games:", games_from_file)
Once the data is loaded, replace games with games_from_file and re-run your filters.
Milestone 5: Search, group, and sort
Now let us dig for deeper patterns.
Search by opponent
target_opponent = "Bears"
for game in games:
opponent = game[1]
team_score = game[3]
opponent_score = game[4]
if opponent == target_opponent:
print(f"Game vs {opponent}: {team_score}-{opponent_score}")
Group by home vs away (count wins)
home_wins = 0
away_wins = 0
for game in games:
home_away = game[2]
team_score = game[3]
opponent_score = game[4]
if team_score > opponent_score:
if home_away == "Home":
home_wins += 1
else:
away_wins += 1
print(f"Home wins: {home_wins}, Away wins: {away_wins}")
Sort by biggest margin
def margin(game):
return game[3] - game[4]
sorted_games = sorted(games, key=margin, reverse=True)
print("Top 3 margins:")
for game in sorted_games[:3]:
print(f"{game[0]} vs {game[1]}: {game[3]}-{game[4]} (margin {margin(game)})")
If you made it this far, you have built a simple analysis pipeline that can answer real questions from game data.
Bonus Exercises: Push It Further with Your Agent
Use your AI assistant to explore more ideas with conditionals and filtering.
Bonus 1: Count Wins and Losses
Goal: Print the total number of wins and losses.
Try prompts like:
- "Help me count wins and losses in my list of games."
- "Print a record like 10-4."
Bonus 2: Find Close Games
Goal: Filter games decided by 5 points (or fewer).
Try prompts like:
- "Show me how to check if the score difference is 5 or less."
- "Print all close games with the point difference."
Bonus 3: Home vs Away Split
Goal: Add a home/away column and compare results.
Try prompts like:
- "Update the CSV loader to include a home_away column."
- "Calculate the win percentage for home games vs away games."
Bonus 4: Add a Streak Counter
Goal: Track the longest winning streak.
Try prompts like:
- "Use a streak counter to find the longest win streak."
- "Print a message if the streak is 3 or more."
Bonus 5: Generate a Simple Report
Goal: Print a short summary paragraph with key findings.
Try prompts like:
- "Write a summary sentence with my total wins, losses, and high-pace wins."