10 Mini Programming Projects

Inspired by @mwclarkson asking for ideas yesterday on Twitter, I thought I’d put together a compilation of 10 mini programming projects I have used in the classroom. Each of them could be used with the language of your choice, although the resources I’ve linked to may contain information specific to the language I used and the year group I used the task with.
Disclaimer: All of the Python code has only been tested in 2.7.x and I occasionally refer to the Python list data structure as an array. Please don’t hate me.

If you use any of these resources and ideas or have any feedback for improvement, I’d love to hear from you either as a comment on here or via Twitter @codeboom

1. Hangman

What is it… guess letters in a pre-defined random word until the entire word is guessed or the number of guesses allowed has been exceeded
How I did it…  in Python with Year 12
Resources… Word game worksheet, Python Skeleton program and Python solution (scroll down)

I started this off as a “guess the word” game only, removing the distraction of having to illustrate the man and forcing students to concentrate on how they would handle the guessing of the letters and checking whether the letters were in the word. It is worth getting the class to work out which functions they will need before providing the sheet containing the function signatures or the skeleton program. There is obviously more than one way of solving this problem so they may come up with different functions and procedures. On the sheet I list the functions like this –  inWord(letter,word) – (Boolean) – meaning the identifier, parameters and return type. I haven’t told you the data types of the parameters but I’m sure they are fairly obvious to figure out – letter is a char, word is a String and guesses is a List.

More advanced students can add in the ‘man’, I found the easiest way was to draw a man in ASCII art style, and store each line as part of an array. Depending on how many turns have gone past, you can ask for different parts of the array to be drawn, like this:

    man = ['________',
           '|       |',
           '|       O',
           '|       |',
           '|      /|\ ',
           '|       |',
           '|      / \ ']

2. Noughts and Crosses

What is it… two players take alternate turns filling in a grid with their symbol, hoping to make a line of 3 in a row
How I did it… in Python with Year 12, and when trying to teach myself jQuery just for fun 😉
Resources… Basic worksheet, Python solution and jQuery solution (scroll down)

I chose to go for the two player option to avoid the problem of implementing AI, although this could be a really good extension task for eager students to think about. The Python solution is a direct extension of the work we did on boxes which I talk about at length in my Python boxes blog post. I realise that the function for checking whether there is a winner is absolutely horrible hard coded nastiness, perhaps you could use it as a good exercise in efficiency to improve it!

3. Blackjack

What is it… draw cards to get as close as possible to 21 without going ‘bust’. When you stick, compare your score to the CPU dealer’s score to see who wins.
How I did it…
 in Python with Year 12
Resources… Blackjack worksheet, skeleton program and solution (scroll down)

This is a firm favourite with my classes – who knew that something involving gambling would be so popular? 🙂 I simplified the game – in this implementation there is only the player and the dealer, the game does not keep track of the ‘cards’ (i.e. you could draw a king more than 4 times, even though there should only be 4 kings in the deck) and ace is always low. This will annoy some students, so they will want to improve the program – which is exactly what you want them to do!

4. Mastermind

What is it… player tries to guess a colour and position combination of four coloured pegs, with the computer giving an indication of how close each guess is
How I did it…
 in Python as a request from a Year 12 student
Resources… Mastermind blog post containing an uncommented solution and suggestions for things students could do with it

Just to be clear, I don’t mean the quiz game with the chair, I mean the board game involving coloured pegs which was probably popular some time in the 80’s/early 90’s. This was actually quite tough to implement so I wouldn’t really recommend getting students to do it from scratch, hence why I have provided the uncommented code with some exercises and ideas for tasks you could do. Alternatively, you could provide a part written program and get them to finish bits of it off.

5. Text adventure game

What is it… a player moves through a fantasy world described in writing, to accomplish some goal
How I did it…
 in Python with Year 12
Resources… ‘Coding the crappy way’ blog post with two methods of implementation, one much better than the other

When I was little, I used to love the text adventure games on my Amstrad. I don’t know what the one I used to play was called, but you were from the empire of ARGC fighting against the evil armies of ARGV – a joke I didn’t get until many years later 🙂 Students like the idea of writing their own text adventure game because they can make it very personal. You could even add items, weapons etc. if you wanted to get really technical!

6. Love Calculator

What is it… the user enters two names and the ‘love calculator’ uses a super awesome algorithm to determine how compatible these two people are
How I did it…
 in PHP with Year 12, but easy to do in jQuery too
Resources… Love Calculator blog post with full tutorial

I really like this task because it appeals to students – yes, even boys – with the whole ‘find out your crush’ thing. Obviously the actual algorithm you use to calculate the compatibility doesn’t actually matter, but it does allow you to teach input, processing and output quite nicely and may be a good intro to web based applications if some of your students are thinking of doing that for their big programming project.

7. Random Quote Generator

What is it… click a button and Mr T will give you a different quote
How I did it…
 in JavaScript (jQuery) with Year 11
Resources… jQuery zero to hero booklet containing full explanation and tutorial and jQuery solution

Obviously if your students have never heard of Mr T, you could substitute any celebrity you like. You could even make it a (hopefully clean) insult generator, or as @mwclarkson and @queen_claire suggested you could do a similar thing to generate your rapper name. This one is quite simple so I think you could easily use it at GCSE or potentially even younger.

8. Shoutbox

What is it… a website where multiple people can write short messages which are stored and published
How I did it…
 in PHP with Year 12/13
Resources… shoutbox task blog post containing bare bones code

This one is excellent because it can be as simple or as complex as you would like, depending on the students you are using it with. You can add lots of extensions to this including limiting the amount of characters, the amount of shouts stored, converting the code to store shouts in a MySQL database, formatting the shouts, adding timestamps, adding a ‘username’, filtering bad language and no doubt other things. It’s even possible to change the interface slightly and go as far as making a very rudimentary working chat room which keeps track of different users – one of my Year 11 students managed to do this.

Depending on how your network is set up, if you have an actual server (i.e. not XAMPP running on someone’s laptop) then students can potentially access this outside of lesson time and write stupid things…so beware!

9. Magic 8 Ball

What is it… allows you to ask the ‘8 ball’ a question and randomly generates a response
How I did it…
 in Python with Year 12
Resources… Magic 8 Ball implementation code

I used this as a very basic task to introduce the use of libraries (specifically the random library) before doing more complex things such as the Blackjack task. I think you could definitely use this for young students as it is very simple and gives fairly instant results. If you are teaching file i/o and serial files, you could extend it into a ‘Fortune Cookies’ program whereby a random fortune is generated and users can also add their own fortune to the list which is stored in a serial text file.

10. Meme Quiz

What is it… the user answers various questions, the answers are then given points and added up, resulting in the user receiving a description/graphic of what their score represents
How I did it…
 in JavaScript, haven’t used it with a class yet though
Resources… quiz implementation code

I feel that I have to point out that I have implemented this as a student task very differently than I would do if I were writing it to actually deploy because I did not want to confuse students and thus put them off. I realise that this solution is not at all elegant but I wanted to avoid having to do things like regular expression parsing for GET variables and hijacking submit events. (If you have no idea what I’m on about, then this proves my point that my ugly solution is actually better for teaching, understanding and getting something working fast!) I also avoided using jQuery in the hope that it may be implementable by a class of students who have learnt a little bit of JavaScript perhaps on codecademy or codeavengers and now want a real project to try out? I think you could successfully complete this with Year 9, although you may have to give them the function for checking which radio button was selected.

(Mastermind picture from Wikipedia, Mr T picture from http://userserve-ak.last.fm/serve/_/27372765/MrT.jpg)


9 thoughts on “10 Mini Programming Projects

  1. After having completed GCSE Computing and deciding to do Computing at A Level, I thought I’d use this summer to try and become better at coding, specifically in Python, which is my favourite language at the moment. Thanks for the great list of projects! I’m going to start with the text adventure one and try and fix my failed attempt at a text adventure that I started last month. Thanks again, you sound like a great teacher! 🙂

  2. Thanks for this list. I made a game of hangman in java. Took a little less than 2 hours. An ambitious grade 11 should be able to do this without too much fuss as well. I used text files as my hangmen as well as a text file full of words to choose at random for single-player hangman.

  3. Just an FYI, Mastermind is older than you give it credit for. It was originally released in 1972. I remember writing a variant of it in BASIC on my Commodore 64.

  4. These look rather fantastic ! I’d like to use some of them with my A level students this year. Unfortunately some of the resource links aren’t working anymore – any chance you could update them, or make the resources available somehow. I would be uber grateful.

    Yours Hopefully…

  5. Thanks for sharing these – they look great for my Year 12’s…As someone else has mentioned, some of the links aren’t working (e.g. the hangman python code ones) any chance you could fix the links?
    Thank you 🙂

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

%d bloggers like this: