Introduction

What's the most unbelievable thing a baseball player has ever done?

  • Joe DiMaggio's 56-game hitting streak that has stood for over 80 years
  • Cal Ripken Jr. playing 2,632 straight games
  • Shohei Ohtani hitting 46 home runs and stealing 26 bases in a season
  • Nolan Ryan throwing 7 no-hitters

What we're building

By the end of this project, you will:

  • Run your first real Python program and see output on screen
  • Learn how to store data in variables to organize information
  • Display formatted statistics using print statements
  • Create a "stat card" showcasing a legendary sports achievement

Why this matters

Every sports broadcast, website, and app displays statistics. The graphics you see on ESPN, the stat overlays during games, the player cards in video games — they're all created by code. Today, you'll write the same kind of code that powers those displays.

Part 1: Quick Start

>button: Download the Starter Pack

Open 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 amazing_achievement.py. Open it, this is where we will be writing our code.

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. It's similar to playing scales on an instrument. You don't learn to play an instrument by copying someone else's notes, you learn by playing the notes yourself.

print("The most amazing statistical achievement in baseball history:")
print("Joe DiMaggio hit safely in 56 straight games.")
print("Date: 1941")

Running the code

Save the file (Cmd + S or Ctrl + S)

You can run the code by hitting the "play" icon in the top right of the screen. Or, you can open the terminal (Cmd + ~ or Ctrl + ~) and type python amazing_achievement.py and press enter.

If everything is working correctly, you should see the output in the terminal:

The most amazing statistical achievement in baseball history:
Joe DiMaggio hit safely in 56 straight games.
Date: 1941

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.

Congratulations! You just ran (and maybe debugged) your first Python program. The text you see in the terminal is the output of your code.

Part 2: Milestones

We're going to build on the code we wrote in the quick start to make it more impressive.

Milestone 1: Print a Single Stat

For this milestone, we're going to print a single stat about the achievement.

print("Joe DiMaggio hit safely in 56 straight games!")

Now, run your code the same way you did in the quick start.

If everything is working correctly, you should see the output in the terminal:

Joe DiMaggio hit safely in 56 straight games!

Now, let's make it more impressive.

Milestone 2: Store stats in variables

In most real-world programs, you'll want to store data in variables so you can reuse it later.

Python lets us store a variety of different types of data in variables. We're going to focus on numbers and text for now.

Check out the code below:

player = "Joe DiMaggio"
games = 56
date = "1941"

print(player)
print(games)
print(date)

Do you see the name = value syntax? This is how we store data in variables. Notice that some of the values are surrounded by quotes. That means they are text (strings), not numbers. Numbers don't need quotes.

We can print the variables by just putting the variable name in the print() function.

Now, run your code the same way you did in the quick start.

Joe DiMaggio
56
1941

Strings are pieces of text. You can combine strings with + to build a longer sentence:

first = "Joe"
last = "DiMaggio"
print(first + " " + last)

That works, but there is a cleaner way to mix text and variables using f-strings.

Now we're ready to move on to the next milestone.

Milestone 3: Combine text and variables

Now, let's combine text and variables to create a more impressive output.

Check out the code below. An f-string is a string that starts with f and uses {} to insert variable values.

player = "Joe DiMaggio"
games = 56
date = "1941"
team = "New York Yankees"

print(f"{player} hit safely in {games} straight games!")
print(f"He played for the {team}.")
print(f"This happened on {date}.")

Now, run your code the same way you did in the quick start.

If everything is working correctly, you should see the output in the terminal:

Joe DiMaggio hit safely in 56 straight games!
He played for the New York Yankees.
This happened in 1941.

Move on to the next milestone.

Milestone 4: Create a Stat Card Display

Now we're going to get really fancy and create a stat card like you'd see in a sports broadcast (well at least one you might see in the 1980s...).

Check out the code below. It's a bit more complex, but don't worry, we'll break it down step by step.

player = "Joe DiMaggio"
team = "New York Yankees"
opponent = "Cleveland Indians"

# The Achievement
games = 56
hits = 91
runs = 36
date = "1941"

# Create the stat card
print("╔════════════════════════════════════════╗")
print("    THE GREATEST HITTING STREAK")
print("╚════════════════════════════════════════╝")
print()
print(f"  Player: {player}")
print(f"  Team:   {team}")
print(f"  vs:     {opponent}")
print()
print("  ─────────────────────────────────────")
print(f"  GAMES:            {games}")
print(f"  HITS:             {hits}")
print(f"  RUNS:             {runs}")
print("  ─────────────────────────────────────")
print()
print(f"  Date: {date}")
print()
print("  \"They say records are made to be broken.")
print("   This one never will be.\"")

Expected Output:

╔════════════════════════════════════════╗
    THE GREATEST SCORING GAME EVER
╚════════════════════════════════════════╝

  Player: Joe DiMaggio
  Team:   New York Yankees
  vs:     Cleveland Indians

  ─────────────────────────────────────
  GAMES:            56
  HITS:             91
  RUNS:             36
  ─────────────────────────────────────

  Date: 1941

  "They say records are made to be broken.
   This one never will be."

Build the card in small steps:

  1. Start with the player, team, opponent, and achievement variables.
  2. Add the top border and title lines, then a blank line with print() to create spacing.
  3. Print the player, team, and opponent lines using f-strings.
  4. Add the stat section with a divider line, then print games, hits, and runs.
  5. Finish with the date and the quote.

Wow, congratulations! You just built your first real Python program. You should be proud of yourself.

If you finished early or would like additional challenges, there are a few bonus exercises below.

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, and f-strings). 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 an HTML Stat Page

Goal: Create a new file called amazing_achievement_html.py that writes an HTML page with your stats and some simple styles.

Try prompts like:

  • "Write Python code that creates a string of HTML for my stat card, then saves it to a file called amazing_achievement.html."
  • "Add basic CSS styles to the HTML so it looks like a simple sports card."
  • "Update my Python file to open the HTML file in my browser after saving."

Bonus 2: Build a Multi-Stat Card

Goal: Print two or three achievements in a row, each with its own variables and output.

Try prompts like:

  • "Help me duplicate my stat card for another athlete with new variables."
  • "Make a function called print_stat_card(...) so I can reuse it."

Bonus 3: Make It Interactive

Goal: Let the user type in the athlete and stats, then generate the output.

Try prompts like:

  • "Show me how to use input() to ask for the player's name, games, and date."
  • "Use the inputs to build the same stat card output."

Bonus 4: Add More Formatting

Goal: Experiment with output style and layout.

Try prompts like:

  • "Make the stat card wider and center the title."
  • "Add a second divider line and align all the numbers."
  • "Change the quote at the bottom and add a source line."

Bonus 5: Create a New Format

Goal: Print the same information in a totally different layout.

Try prompts like:

  • "Turn the stat card into a scoreboard-style output."
  • "Print the stats as a table with columns."
  • "Make a 'trading card' layout with a short bio section."