Teaching Coding, Part 6

We spent most of yesterday’s class sharing each others’ games. The girls came up with some very entertaining ones. For example, this one made use of Robert Frost’s famous poem, The Road Not Taken:


In this game, a tardy student has to avoid getting caught by the principal!


Another one reads like an interactive novel, with the user deciding if the protagonist is male or female, if a character has a key to a mysterious trunk, etc. Her code fills eleven pages when it’s pasted into Word!

In the next class, we are going to analyze our final Python program, Hangman. This program introduces ASCII art, lists, for loops, and else-if statements. 


Teaching Coding, Part 4

pythonOn Day 3, I introduced the Python v3.3 programming language, which is very powerful yet easy to understand. It is free, and you can download it here. It installs the interpreter as well as IDLE, which stands for Interactive DeveLopment Environment. IDLE is where the user writes and runs his or her programs.

For our main text, we’re using Al Sweigart’s Invent Your Own Computer Games with Python, 2nd Edition. He has an excellent website, Invent with Python, where you can download a free pdf version of the book. One of the most useful features of the site is the diff tool. After typing in a program from the text, a student can upload her version, and the diff tool compares it to the text’s version. This is very helpful when debugging the programs!

Our first program was the traditional “Hello World!” (with a little extra thrown in) :

#This program says hello and asks for your name
print('Hello World!')
print('What is your name?')
myName = input()
print('It is nice to meet you ' + myName)

This simple little program teaches commenting, calling functions (print and input), string concatenation, and variable assignment.

We then explored some features of IDLE: executing arithmetical expressions, storing values in variables, writing strings, saving and running programs. To wrap up the day’s lesson, we previewed if/then statements.The homework assignment was to write a simple program that asks for user input and responds to it. Here’s what one student came up with:


And here is some typical output:

pasword output

Day 4 continued what we began in Day 3. We typed in a Guess the Number Game, which had the computer generate a random number, and the user tried to guess what it was. The game utilized a “while loop”, so the girls learned about blocks of code, comparison operators, and Boolean values.

After some discussion, we realized that all computer programs contain just four elements:

1. Expressions

2. Assignment statements

3. Flow control statements

4. Input/output functions

Coming up: defining our own functions!

Entering The World of Coding

Women are underrepresented in computer science, so I have agreed to offer a three-week minicourse on coding at Harpeth Hall during Winterim, a between-semesters period for alternative curricula. My only previous experience with computer programming is from more than 30 years ago, when I had to take a course in FORTRAN for my engineering degree. I do not have happy memories of that experience.

Fortunately, there are many more coding languages to choose from these days, and there are some very entertaining and enjoyable ways to learn them. I’m learning Python, and I’m using two resources. The first one is the book Hello World! by Warren and Carter Sande. Hello World

It’s written at a level schoolkids can understand, but adults will also find it very helpful. It’s filled with useful illustrations, and best of all, it has a link to a downloadable file that installs a Python IDLE (a graphical user interface that allows you to write and run Python programs on your computer), so you can work through all the examples as you read. There is a brand new edition coming out in two weeks, and the link above will take you to the Amazon page for that edition.

Here’s a screenshot of one of the first exercises. It’s a program that converts any Fahrenheit temperature to Celsius:


The second resource I’m using is Codecademy, which hosts all kinds of online courses for people who want to learn coding. Here’s a screenshot of a typical lesson:


The lessons are easy, entertaining, and you can learn at your own pace. Codecademy offers courses in jQuery, JavaScript, PHP, Python, and Ruby. And guess what? It’s free!

I’ll be posting later in the year on how the course goes, and what my students think about the subject. Meanwhile, here is a nice introduction to what is involved in programming.