9-12, Advanced Topics, AP Computer Science Principles

Playing Around with Simulations

Simulations has always been a fun topic to explore with my computer science students.  I know AP only includes it for a lesson or two, but I luxuriously explore it for a few periods since my students have already had some programming experience.  If your students are familiar with Python, I’ve got a simulation for them below!

For our warm-up, we start with some entertaining examples:  How can I drink bubble tea to ensure that I don’t finish the tea before the bobas? and/or Lemonade Stand Game (ahh…a classic…).  After some time to play, we discuss:

  • What makes these a simulation?
  • What are the simplifications they make? Why?
  • What are the assumptions?
  • What are the benefits of running a simulation over the real thing?
  • What are the detriments?
  • How can you get closer to the “actual” results?

Next, we look at the data from some more advanced simulations.  “Why do human beings speak so many languages?” from The Conversation is a good article to discuss because you’re able to compare the results of their simulation of how languages spread and are created to how many languages there actually are in Australia.  Additionally, a frequency chart (histogram) is provided which provides an opportunity to remind students of what a histogram is and why it is useful in this case.

This year, I also brought in FiveThirtyEight’s Election Forecast to hypothesize what type of data might be useful when trying to predict election results.  This was a little hairy because I didn’t want to add additional stress to my students or bring up difficult emotions.  However, I want my students to understand the data they’re hearing and seeing on the news and social media.  I also feel that by this point in the year, we have a classroom culture in which they feel safe saying they’re uncomfortable.  As a bonus, they have some really interesting visualizations of their data that were a nice preview for our Data unit later in the year.

Finally, we spend the majority of our time exploring a simulation of a disease spread I wrote in Python.  Again, a potentially touchy topic in the midst of a pandemic, but an opportunity for discussion.  In this activity, we make a prediction about the relationships between the population, percent initially infected, and time for everyone to be infected.  After running the simulation to get data, we write the program together to make a histogram.  From there, students choose an additional variable or constraint to add to the program and analyze.  This activity allows us to continue discussing the simplifications made in simulations and identify how useful simulations are as well as controlling variables and the scientific method. (All files needed)

For another fun simulation I usually use during our review at the end of the year, check out the UN’s Stop Disasters game!