Last fall, I taught four sections of a survey course on information systems to freshmen who have chosen not to study information systems. Still, regardless of major, all students today benefit from knowing at least the basics of coding.
To this end, the other two instructors and I spend one class covering the basics of object-oriented programming.1 For the next three classes, we introduce simple programming concepts such as variables, print and if-then-else statements, lists,2 functions, and for and while loops. In CIS236 and its cousin CIS235, we only scratch the surface of one of the today’s most powerful and popular programming languages.
At the end of the Python module, I stitch everything together with some examples that build upon what we have learned so far. My favorite is a basketball-inspired one that pokes fun at my lack of skills. The script calculates my game-by-game and aggregate shooting percentages.
Although it’s far beyond the scope of the class, there’s so much more you can do with Python, especially when you consider its libraries. After reading Clive Thompson’s excellent book Coders: The Making of a New Tribe and the Remaking of the World, I thought that I’d revisit last semester’s script and improve upon it.
Improving on the First Iteration
I knew that I would first have to gather and store shot and game data in simple lists.3 After that, creating the bar chart would be pretty straightforward. I’m sure that I could have done it in many different ways, but I chose to visualize the results with matplotlib.pyplot and numpy.
Give it a whirl yourself below by hitting the play button. Note that the bar chart appears at the bottom on the right. You’ll most likely have to scroll down to see it.
Click here to download this script on my GitHub.
Or, if you like, watch the video of it below:
I’m hardly an expert on all things Python, but that’s the point: It’s not that hard to improve upon a script and, dare I say, add a little flair. Beyond that, I can think of worse ways to spend a few minutes on a Sunday morning than learning more about Python and some of its libraries.
What say you?
- We coordinate our efforts to ensure consistency.
- Aka, arrays in many other languages.
- I use both game_list and pct_list in the code above.
Filed Under 📁