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!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s