Sunday, January 13, 2019

Python first lesson - Peanut Butter Jelly Time!

The first week of the semester is in the books.  Students have been reminded of expectations, and have settled into the new semester.  I changed the grading percentages around a bit in several classes: adding an effort grade to my entry-level classes and for my AP class increasing the percentage that tests count towards the grade and decreasing the percentage for homework/programming assignments.  The effort grade is something that our art teachers do.  It is a good way to remind freshmen to remain on task and take an entry-level elective class seriously.  Increasing the percentage of tests in the AP class is in line with what our other AP teachers are doing and also what I have read in the APCS A FaceBook group.

The code reading/welcome back activity from last week's blog went well and the students enjoyed it and felt that it was helpful.  They have asked for more of this, so my plan is to alternate between subgoal labeling and code reading to introduce new topics for the second semester.

Peanut Butter Jelly Time

This week is one of my favorite weeks of the year!  The Exploring Computer Science class is beginning its nine weeks of coding.  I tell students how my first programming class in high school (Apple BASIC) got me hooked and led to a college major that I thoroughly enjoyed and then to a
fulfilling career that took me all over the world.

But before we start programming I take a day to introduce some terms and concepts by having the students write instructions for making peanut butter and jelly sandwiches.  The students work in pairs so they can begin seeing what paired programming will feel like.  Inevitably, the first confident pair reads their instructions and correctly remembers to take the plastic tab off of the bread bag but forgets to untwist the closed bag.  I let the pair make one change "on the fly".  At that point, the bread slices are out of the bag and on the plate and the next typical error is that students instruct the computer to turn the peanut butter jar lid counter clockwise.  But without picking up the jar first the lid simply spins the jar around and around on the table.  They have fun and we learn several different computer terms that we use the following day.

Students learn that making the sandwiches has instructions and that some of the instructions operate on things.  We talk for a bit about Python being a language that has instructions and that some of these instructions need parameters.  We pick up a jar and unscrew a lid.  I don't show these as instructions like pickup(jar) and unscrew(lid).  This may be an idea for next year.  We also talk about the idea of iterative development and that as we learn new things and figure things out we go back and refine programs and make them better in the same way that we made a better set of instructions that got us closer and closer to that peanut butter sandwich.  As students get close and think they have the full set of instructions, someone runs into a problem and exclaims "But that isn't what I meant!".  This is another good stopping point to remind that students that with programming many things can be intuitive but sometimes instructions don't always work the way we think they should.

Python print() and numbers

The first day of instruction and practice is easier having doing the fun activity first and introducing many of the terms that we use.  We use Idle to enter in instructions and see how they run and begin with print() instructions.  We print strings first and spend time making sure everyone can find the parentheses and quotation marks on the computer keyboard.  Then we move into numbers and talk about keys that represent the operators.  It takes time to make sure that everyone can find all of the correct keys.  We put the operators together and do a quick refresher on PEMDAS and discuss that computers follow the same operator precedence that we do.  We finish off the instruction by having the students learn that the comma can be used to print more than one string or number or operation.

I use the website to have the students practice.  Snakify is divided into theory, steps, and practice.  I prefer to walk through examples with the students instead of using the theory section.  But I have students complete all of the steps and then work in pairs to complete the practice problems.  Then I finish off each lesson with a small project.  For the first lesson we typically use ASCII art with sets of print() statements.

After the first lesson, it is usually fairly easy to see the students that are hooked, and then it is time to try to add to that number.

Royalty Free images from

Sunday, January 6, 2019

Ice Castles and Code Tracing / Reading

Dillon, CO Ice Castle
It's the last day of Christmas break before tomorrow's work day and students' return on Tuesday for the new semester.  It was a wonderful break of catching up with family and friends as well as some fun activities.  Last night was a great final trip to Dillon, CO and a walk through an full scale ice castle ( with friends.  The ice castle was beautiful with lights coming through the ice making it glow in different colors.  The end product was beautiful, but it was very slowly built up from a set of scaffolding with lights built in and then layer and layer of water turned to ice.  It is  a good metaphor for the building up of skills needed in the AP Computer Science A class.

Also, over break I had the opportunity to do some reading.  One very good blog post from Austin Cory Bart was a CS1 Literature Review (  This blog post is a look at what I want to do with one of the topics from the literature  review:  Code reading and tracing. 

Starting the new Semester

I plan to start the new semester with a review activity that covers all of the topics we visited during the first semester with a special look at some of the most complex or difficult parts for the students.  In the non-AP version of programming that I taught in previous years, I did this as a code along activity where we wrote code together to go through these concepts.

Enter the Literature Review...  One of the early topics covered was the importance of code reading leading to good or better code writing.  Code reading is not something I have emphasized.  The concept makes sense.  Students who are good writers also tend to be those who read a lot.  The same concept can be true for Computer Science as well.  Reading code can lead to better writing of code.  Extending that idea, reading good, well-written code is important.  In the same way that reading abbreviated text messages or poorly written text does not lead to good writing skills.

I plan to combine the code reading assignment with think/pair/share which is something I use fairly often in my lower level classes.  The Literature Review also covered the importance of collaborative experiences which is an important soft skill in the working world of IT.

Code Tracing and Reading

One of the confusing points for me was references to Code Tracing and Code Reading as two different things.  So I went back and read one of the research articles, Relationships between reading, tracing and writing skills in introductory programming by Mike Lopez, Jacqueline Whalley, Phil Robbins, and Raymond Lister (  To me, code tracing is the equivalent of knowing the meanings of words and code reading equates more to the idea of reading for comprehension.

Code tracing is the ability to read a line(s) of code and explain what it does:
a = 4;
a += 5;
Add 5 to the current value of a which is 4 and set a to the new value of 9.

Code reading is the more advanced concept of looking at a block of code and being able to explain what it does.
sum = 0;
for (int i=1; i <= 10; i++)
     sum += i;
Sum the values 1-10 and print out that sum.

Beginning of the Semester Activity

With those definitions in mind, I see that my students have plenty of opportunities to trace code but not that many opportunities to read larger amounts of code for comprehension. Students can read small blocks of code such as the example above, but not many opportunities to read an entire class and runner for comprehension.

The code example that I am using is Rainfall.  The class stores the name of a city and an array of monthly rainfall totals.  The class processes the array to calculate min and max months, total and average rainfall and a standard deviation.  The runner class reads in CSV lines from a file and then processes the lines using the comma as a delimiter.  Students will also have the opportunity to review code again that does formatted printing as it is a topic that still confuses several.

The methods in the Rainfall class are things like get1(), get2()... and several variables are set to x and y.  Students will be assigned methods to read and review.  Then they will work with a partner to compare and together assign new method and variable names that are descriptive.  After that I will have the students discuss their assigned methods with the class.

Here are the classes and data file that we will use: