A Northwestern University joint initiative of Medill School of Journalism, Media, Integrated Marketing Communications and the Robert R. McCormick School of Engineering & Applied Science. Northwestern University joint initiative of Medill & McCormick School of Engineering.

Five mini programming projects for the Python beginner

After Shelly wrote this post, Webucator, a company that provides Python training, volunteered to create solutions for these projects. They’ve made a series of videos that’ll help you out if you need it.

Learning a new programming language is both the most exciting and the most humbling experience. For me, that language has recently been Python, which I’ve been learning over these last few months. And as every coder knows, the best way to learn a language is to apply it in a project. But what happens when you don’t have a giant, ambitious project? For me, that’s where the sandbox comes in. Why not build a few sandcastles before piling up the rocks to our grand ol’ castle?

With that in mind, here are five mini programming projects to get you started on learning Python. The exact solutions aren’t here — that’s where the most important learning comes into play — but there are hints as to the concepts that you should be using. And remember, Google is your friend!

1. Dice Rolling Simulator

The Goal: Like the title suggests, this project involves writing a program that simulates rolling dice. When the program runs, it will randomly choose a number between 1 and 6. (Or whatever other integer you prefer — the number of sides on the die is up to you.) The program will print what that number is. It should then ask you if you’d like to roll again. For this project, you’ll need to set the min and max number that your dice can produce. For the average die, that means a minimum of 1 and a maximum of 6. You’ll also want a function that randomly grabs a number within that range and prints it.

Concepts to keep in mind:

  • Random
  • Integer
  • Print
  • While Loops

A good project for beginners, this project will help establish a solid foundation for basic concepts. And if you already have programming experience, chances are that the concepts used in this project aren’t completely foreign to you. Print, for example, is similar to Javascript’s console.log.

2. Guess the Number

The Goal: Similar to the first project, this project also uses the random module in Python. The program will first randomly generate a number unknown to the user. The user needs to guess what that number is. (In other words, the user needs to be able to input information.) If the user’s guess is wrong, the program should return some sort of indication as to how wrong (e.g. The number is too high or too low). If the user guesses correctly, a positive indication should appear. You’ll need functions to check if the user input is an actual number, to see the difference between the inputted number and the randomly generated numbers, and to then compare the numbers.

Concepts to keep in mind:

  • Random function
  • Variables
  • Integers
  • Input/Output
  • Print
  • While loops
  • If/Else statements

Jumping off the first project, this project continues to build up the base knowledge and introduces user-inputted data at its very simplest. With user input, we start to get into a little bit of variability.

3. Mad Libs Generator

The Goal: Inspired by Summer Son’s Mad Libs project with Javascript. The program will first prompt the user for a series of inputs a la Mad Libs. For example, a singular noun, an adjective, etc. Then, once all the information has been inputted, the program will take that data and place them into a premade story template. You’ll need prompts for user input, and to then print out the full story at the end with the input included.

Concepts to keep in mind:

  • Strings
  • Variables
  • Concatenation
  • Print

A pretty fun beginning project that gets you thinking about how to manipulate userinputted data. Compared to the prior projects, this project focuses far more on strings and concatenating. Have some fun coming up with some wacky stories for this!

4. TextBased Adventure Game

The Goal: Remember Adventure? Well, we’re going to build a more basic version of that. A complete text game, the program will let users move through rooms based on user input and get descriptions of each room. To create this, you’ll need to establish the directions in which the user can move, a way to track how far the user has moved (and therefore which room he/she is in), and to print out a description. You’ll also need to set limits for how far the user can move. In other words, create “walls” around the rooms that tell the user, “You can’t move further in this direction.”

Concepts to keep in mind:

  • Strings
  • Variables
  • Input/Output
  • If/Else Statements
  • Print
  • List
  • Integers

The tricky parts here will involve setting up the directions and keeping track of just how far the user has “walked” in the game. I suggest sticking to just a few basic descriptions or rooms, perhaps 6 at most. This project also continues to build on using userinputted data. It can be a relatively basic game, but if you want to build this into a vast, complex word, the coding will get substantially harder, especially if you want your user to start interacting with actual objects within the game. That complexity could be great, if you’d like to make this into a longterm project. *Hint hint.

5. Hangman

The Goal: Despite the name, the actual “hangman” part isn’t necessary. The main goal here is to create a sort of “guess the word” game. The user needs to be able to input letter guesses. A limit should also be set on how many guesses they can use. This means you’ll need a way to grab a word to use for guessing. (This can be grabbed from a pre-made list. No need to get too fancy.) You will also need functions to check if the user has actually inputted a single letter, to check if the inputted letter is in the hidden word (and if it is, how many times it appears), to print letters, and a counter variable to limit guesses.

Concepts to keep in mind:

  • Random
  • Variables
  • Boolean
  • Input and Output
  • Integer
  • Char
  • String
  • Length
  • Print

Likely the most complex project on this list (well, depending on just how intense you went with the adventure text game), the Hangman project compiles the prior concepts and takes them a step further. Here, outcomes are not only determined based on user-inputted data, that data needs to be parsed through, compared, and then either accepted or rejected. If you want to take this project a step further, set up a hangman image that changes!

Like what you see?

Northwestern University Knight Lab advances news media innovation through exploration, experimentation and education. The Lab's free publishing tools help to make information more meaningful and promote quality storytelling on the Internet.

About the author

About Posted on June 5, 2014 Posted by

Shelly Tan

Designer, Journalism and Art Theory and Practice (2014)

Designer interested in information architecture and user-oriented experiences. Former intern at NPR Visuals.

  • Van Helmont

    Interesting! I’ve already started! I find it very useful for acquiring early practice. Thanks!

  • Awesome! Let us know how it goes.

  • Sarah Wooller

    thanks I wanted some suggestions for my son and hangman is a great idea.

  • PETZ

    I just wrote the dice program as my first bit of python coding, and I’m really digging it so far. For future readers: if you want to make it a bit more challenging, have the program accept command line arguments for number of sides on the dice and how many times to roll it. I’ll be tackling the other four challenges soon.

  • Imaculate

    Awesome!

  • Exist

    I just wrote the dice program and my suggestion if you want to improve even more try to give the user a chance to determine whether they want to reroll the dice or not. and PETZ nice idea! I’m gonna try it.

  • Nice! Thanks for reading.

  • Great suggestion. Thanks!

  • beastwork

    I just finished the projects and for a newb like me this was a lot of fun. It really helped me reinforce some skills and by the time I got to the Project 5, I was able to breeze right through.

  • Pou Lin

    Cool projects, it helped me to make my base strong and also enjoyed creating it.. And keep me going further ^__^ thank you Shelly Tan 🙂

  • rolika

    I wrote the guess-the-number programm, but it is some more challenging to write the opposite, when the computer guesses your number!

  • Tyler Leadbetter

    I need the code for the hangman one

  • TJmaxal

    Great prompts!

  • Berat Ademi

    Those are some nice projects 😀 I wrote my first python code on the die rolling simulator. If you’d like you could also add an advanced part there that asks the user to programm a simulator that asks for zhe number of dices used ;P

  • pranjal saxena

    I just successfully till 2nd project and working on 4th one that seems to be very interesting! Thanks buddy ….hope for the new projects…please mailed me on pranjal.saxena2012@gmail.com thank you. 🙂

  • Azurasy

    Thanks for the text based adventure idea, it was actually fun to make. here my code if you want to try it: https://repl.it/CXcQ/2

  • Nice! Glad it was helpful.