Chapter 12: Projects

You’ve learned enough about programming to write useful programs. There are obviously many things missing, such as saving things to disk and making nice user interfaces. There are also more concepts to introduce, such as structures and objects. I plan to write another book of intermediate-level programming to cover some of these things. In the meantime, practice your new skills with these projects:

Write a program to display the lyrics of the song, “The Twelve Days of Christmas.” A lot of it is repetitive. Don’t type in all the repetitive stuff; let the computer do the work for you.

Write a program to keep track of your contacts. Each contact will have a name and a phone number. The program should be able to add a new contact, look up an existing contact (by name, giving you their phone number), and remove a contact.

Write a program to play “rock, paper, scissors” with the user. Keep track of the score. You’ll need a way to have the computer come up with one of these randomly. Use this function, which is already defined by the language:

x = random(3)

That means, “Set the variable x to an integer less than 3.” Each time you call it you will set x to the number 0, 1, or 2, randomly. You can change the “3” to anything, but for this game you’ll want to keep the “3” since that’s how many kinds of objects there are.

Write a program to play tic-tac-toe with the user. This one is quite advanced, but doesn’t use any programming concepts that you haven’t yet learned. You’ll just have to combine them in ways that are more sophisticated than anything we’ve done so far.