Introduction:
What makes one athlete better than another?
- Is it throwing for the most yards?
- Winning the biggest games?
- Being consistent year after year?
- Excelling across multiple skills?
What we're building:
- Calculate rating scores to rank players based on their performance metrics
- Summarize performance with dynamic rankings for individual players
- Create a clean, formatted stat card showcasing each player's stats and overall rating
Why this matters:
One easy way to think of sports ranking is to think of it as similar to ranking students in a class. Just as grades combine homework, quizzes, exams, and engagement into one final score, a player rating system combines different stats—like passing yards, touchdowns, and completions—into a single number. Rating systems measure overall athleticism and an athlete's current readiness, helping to predict future success.
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.
This time, there is no python file provided for you (only an AGENTS.md file). You will create the python file yourself!
To do this:
- Find the "New File" icon in the top left of the screen next to the folder name in the file explorer (it looks like a document with a plus sign in the bottom right).
- Click on the icon to create a new file.
- Name the file
player_rating_system.py. The.pyextension is important, it tells your computer (and Cursor) that this is a Python file. - Click on the file to open it.
Writing the code
It's important to type in code manually at first, instead of copying and pasting. This will help your brain learn the code and remember it later.
print("Welcome to the Player Rating System!")
Running the code
Save the file (Cmd + S on Mac or Ctrl + S on Windows/Chromebook)
If you want Cursor to auto save (recommended):
- Press (
Cmd + PorCtrl + P) - Type: Auto Save
- Select Toggle Auto Save
You can run the code by hitting the "play" icon in the top right of the screen. Or, you can open the terminal (Ctrl + ~) and type python player_rating_system.py and press enter.
If everything is working correctly, you should see the output in the terminal:
Welcome to the Player Rating System!
If you got an error message, that's OK! You have a helpful AI assistant to help you fix it. Open your AI agent in Cursor (Cmd + L or Ctrl + L) and ask it to help you fix the error.
Once everything runs successfully, move on to the next milestone to build the Player Rating System!
Part 2: Project Milestones
Milestone 1: Store stats in variables
In most real-world programs, you'll want to store data in variables so you can reuse it later. In other words, variables are containers for storing data values.
We're going to focus on storing numbers and text for this project. We need to store player_name, passing_yards, touchdowns, and completions.
These values might represent average player stats for a given season, or a single game, or a single match.
Check out the code below:
player_name = "Patrick Mahomes"
passing_yards = 5250.0
touchdowns = 41.0
completions = 435.0
print(player_name)
print(f"Passing Yards: {passing_yards}")
print(f"Touchdowns: {touchdowns}")
print(f"Completions: {completions}")
When storing text (strings), values must be surrounded by quotes. Numbers don't need quotes.
Note that our numbers have decimal points, which means they are floats (floating point numbers). In Python, numbers are either ints (whole numbers) or floats (numbers with decimal points).
We can print these variables by just putting the variable name in the print() function.
Now, run your code the same way you did in the quick start.
Patrick Mahomes
Passing Yards: 5250.0
Touchdowns: 41.0
Completions: 435.0
Now we're ready to move on to the next milestone!
Milestone 2: Simple overall rating calculation
Now we're going to calculate the overall rating for the player. We'll do this by multiplying each stat by a weight (how important it is) and then adding the weighted stats together. As you might imagine, weights are also decimal numbers (so floats).
When dealing with weights, a 1.0 weight means that the stat is worth 100%. A 1.5 weight means that the stat is worth 150% (so boosted by 50%). A 0.01 weight means that the stat is worth 1% (useful for scaling down large numbers like yards).
In the example below we are scaling passing yards down (since they're in the thousands), boosting touchdowns significantly (since they're the most valuable), and giving completions a smaller weight.
score = (passing_yards * 0.01) + (touchdowns * 2.0) + (completions * 0.05)
print(f"{score:.1f}")
Two things to note here:
- We are using parentheses to group the calculations. This is for order of operations (like in math!). We want to make sure that the calculations are performed in the correct order.
- We are using an f-string to format the decimal number output. The
{score:.1f}syntax means we want to format the number to 1 decimal place.
If everything is working correctly, you should see the output in the terminal:
156.3
Ta-da! You just turned raw player statistics into a single overall rating that can be used for comparison and ranking.
Now, let's make it more impressive.
Milestone 3: Create a Rating System Display
Let's format our stats into a nice looking stat card like you'd see in a sports broadcast (well at least one you might see in the 1980s...).
Add the following code to the bottom of your file, right after the overall rating calculation.
# New code for our stat card:
scoreboard_width = 32
print("=" * scoreboard_width)
print(" PLAYER OVERALL SCORE ")
print("=" * scoreboard_width)
print(f" Player: {player_name}")
print("-" * scoreboard_width)
print(f" Passing Yds: {passing_yards}")
print(f" Touchdowns: {touchdowns}")
print(f" Completions: {completions}")
print("-" * scoreboard_width)
print(f" Overall Score: {score:.1f}")
print("=" * scoreboard_width)
print(" \" When you add it all up,")
print(" The numbers speak for themselves.\"")
Expected Output:
================================
PLAYER OVERALL SCORE
================================
Player: Patrick Mahomes
--------------------------------
Passing Yds: 5250.0
Touchdowns: 41.0
Completions: 435.0
--------------------------------
Overall Score: 156.3
================================
" When you add it all up,
The numbers speak for themselves."
Try changing the scoreboard_width variable and re-run your code to see how it affects the width of the stat card.
If you made it this far, congratulations! You've successfully built a player rating system. From your very first Python program to this, you've come a long way. Give yourself a big clap! 🎉
If you'd like to go further, there are a few bonus exercises below that you can explore with your AI assistant (use Cmd + L or Ctrl + L to open the AI agent).
Bonus Exercises: Push It Further with Your Agent
Use your AI assistant to explore what's possible with the same building blocks you just learned (variables, print statements, f-strings, and calculations). Open the AI agent in Cursor with Cmd + L (or Ctrl + L), then type your prompts in the chat panel on the right. Each idea below is meant to be done by prompting your agent and experimenting.
Bonus 1: Make It Interactive
Goal: Let the user type in the player's name and stats, then generate the rating output.
Try prompts like:
- "Show me how to use
input()to ask for the player's name, passing yards, touchdowns, and completions." - "Use the inputs to calculate the overall score and display the same rating card."
- "Add validation so the program asks again if someone enters text instead of a number for stats."
Bonus 2: Build a Multi-Player Ranking System
Goal: Create ratings for multiple players and display them in a ranked list.
Try prompts like:
- "Help me create variables for three different quarterbacks with their stats."
- "Calculate the overall score for each player and store them in a list."
- "Print all players sorted by their overall score from highest to lowest."
- "Create a formatted ranking table showing each player's position, name, stats, and overall score."
Bonus 3: Create Reusable Functions
Goal: Turn your rating calculation and display code into functions you can reuse.
Try prompts like:
- "Make a function called
calculate_rating(...)that takes passing yards, touchdowns, and completions as parameters and returns the overall score." - "Create a function called
display_player_card(...)that takes a player name and stats, then prints the formatted rating card." - "Use these functions to display rating cards for multiple players."
Bonus 4: Add More Formatting and Alignment
Goal: Experiment with output style, alignment, and visual improvements.
Try prompts like:
- "Make the rating card wider and center-align the title."
- "Right-align all the stat numbers so they line up in a column."
- "Add color to the output using ANSI color codes."
- "Create a horizontal bar chart showing how each stat contributes to the overall score."
Bonus 5: Customize the Rating Formula
Goal: Experiment with different weighting systems and rating formulas.
Try prompts like:
- "Let me input custom weights for passing yards, touchdowns, and completions, then recalculate the rating."
- "Create a new rating formula that also considers passer rating or yards per attempt."
- "Add a comparison feature that shows how a player's rating changes when you adjust different stat weights."
- "Display both the old and new ratings side-by-side when weights change."