By popular demand, we're spending our final block on object-oriented programming.

 

By the end of block four, students in Introduction to Python had been exposed to all of the essential concepts of introductory computer programming: variables, input/output, conditional statements, loops, functions, strings, lists, text files, and dictionaries. So, there were a number of different paths that the course could have taken in block five. I described several possibilities to the students and took a class vote. By an overwhelming margin, the students chose to study object-oriented programming (OOP) in block five.

OOP is one of the major conceptual ideas in modern-day computer science. In the Intermediate Python class, it was the very first topic we studied, back in September. It is also a difficult topic to wrap your head around the first time you see it, so I am happy that the Introduction to Python students will be exposed to the basic idea this year, so that they will be prepared to study the material at a more sophisticated level in Intermediate Python. Additionally, when creating OOP lessons, it is easy to include a review of strings, lists, and dictionaries at the same time. I hope this will allow the students to fill in any gaps they might have in their knowledge of this basic material.

Introduction to Python students had already seen objects much earlier in the year, without really knowing it, when they created turtles and then gave their turtles commands to draw pictures on the screen. The code to create a turtle and have it draw a circle of size 50 on the screen looks like this:

from turtle import *

myturtle = Turtle()

myturtle.circle(50)

where the "dot notation" on the last line is how you give the turtle named myturtle the command to draw the circle. In a similar way, students wrote code for a Die class, which allowed them to write this code to create a die with 6 sides and print out the result of rolling that die.

from die import *

mydie = Die(6)

print(mydie.roll())  

We will spend the rest of the school year learning how to model increasingly sophisticated real-world objects in code, including a notebook (which will be implemented as a list of strings) and a scoreboard keeping track of how many points all the players on one team in a basketball game have scored (which will be implemented as a dictionary). I hope students will both enjoy and appreciate this topic.  

--Steve Gregg