Making Class Memorable with a Basketball-Inspired Python Example

A little program to calculate game logs and stimulate student interest.

“I cannot be a teacher without exposing who I am.”

—Paulo Freire

Introduction

For the last twenty-something years with rare exception, my five best friends from Carnegie Mellon and I have upheld an annual tradition: we get together in a different city, catch up, eat well, and play three-on-three-basketball. The photo above comes from this year’s match in Colorado. (Note that the backboard’s no-dunking sign couldn’t be less relevant to these six individuals, but I digress.)

It’s an understatement to say that we take the hoops part of our weekends pretty seriously. If the uniforms don’t tip you off, let me give you a little more information. There’s the frequent smack talk that takes place during the planning stages. Of course, we film the series. Beyond that, we rent a gym to ensure that the weather isn’t a factor. For the past three years, we’ve hired a proper referee because we can’t be remotely objective in the heat of battle. As for our team name, it’s the same moniker as the one that we gave ourselves during our CMU years: Reservoir Dogs, a nod to Tarantino’s masterpiece.

Why not demonstrate an important programming concept in a memorable way?

My favorite part of the weekend is watching the game footage as my friend Chris tallies the stats. Over the years, we’ve had to create a few new categories because the six of us find traditional basketball measures lacking. For instance, no NBA stat accurately captures really bad shots. This led to the invention of uglies, a category that includes airballs, bricks, and other ill-advised shots.

You can see some of these shots in action in the following 2006 video from La Jolla, CA.

Shooting a decent percentage isn’t really an option for me, especially on a consistent basis. I’m downright thrilled to flirt with 30 percent in any given game.1 My assist numbers usually aren’t too shabby, but I credit my teammates far more than myself. To be fair, occasionally I will channel my inner Jason Kidd.

Finding a Teaching Hook

I was thinking about this last week as I was demonstrating Python’s for loops to my CIS235 students and now to nest them within each other. I had already shown them simple while loops a little “while” ago.2 To this end, I wrote the following program to calculate per-game and aggregate shooting percentages. Give it a try yourself if you like below.

The nested loops above (i and j) demonstrate how a programming language—in this case, Python—cycles through a previously unknown number of events: games and shots, respectively. It would not take that much effort for a curious student to tweak my code above for any number of different scenarios. Case in point: A couple of changes could turn the program above into a rudimentary weekly sales-conversion tool. (We cover customer relationship management [CRM] this week.)

Simon Says: Good professors find ways to make class memorable for their students.

No, this code isn’t terribly complicated and I don’t expect to use it in lieu of our paper-based method of keeping stats. What’s more, unless they work for sports organizations, I don’t expect my students to use anything exactly like this when they graduate. Still, it demonstrates an important programming concept in what I hope is a memorable way. To quote Vincent Vega from Pulp Fiction, personality goes a long way (NSFW).

My favorite professors did the same for me. Why not pay it forward?

Feedback

What say you?

Footnotes

  1. In case you want to see a detailed statistical breakdown of last year, click on the interactive Tableau dataviz.
  2. Not a bad pun, eh?.

philanimated

Navigation

BACKRANDOMNEXT

YOUR AD HERE

Filed Under



Enjoy this post? Click here to subscribe to this RSS feed or here to sign up for my bi-monthly newsletter.


1 Comment

  1. Jim

    Hi Phil!

    How strange to see a crowd of familiar faces in uniform, after so long. I miss you guys.

    All the best!

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *