Learning Python, Tutorial 10: A Python Game

Well here we are, tutorial ten. Well done if you have followed the Python tutorials this far, you are well on your way to becoming a programmer.

Now you get to step up and write a game!

You’ll need to Watch the video below to see it in action. I’ll run through what I want you to do below it.

Great, now that you have seen it work, here are the points I want you to include in your Python game: Continue reading

Learning Python, Tutorial 9: For Loops

Last time we looked at While loops, which ran until we told them to stop, by meeting some condition. This time we’ll be playing with For loops, which run a set number of times. You can follow along with the video, or the text here in the post.

Don’t forget you can sign for updates FREE, by using the box to the right. The code sample is available here: Tutorial 9 – For loops code example

Lets start with a code example, and then talk about what it is doing. Open your Python IDLE GUI, start a new file and type: Continue reading

Learning Python, Tutorial 8: While Loops

In this tutorial we’ll be look at loops within Python, specifically the while loop. As usual, you can follow the video, or the text and code below. You can find the code example here: Tutorial 8 – While loops

A loop is simply a bit of code that executes again and again until something happens to break it (picture a circle). It’s probably easier to understand when you see it in action, so open your Python IDLE GUI and we’ll get cracking with an example… Continue reading

Learning Python, Tutorial 7: If, Else & Elif

In this lesson we are going to revisit the dice rolling we did in Tutorial 5, only this time we are going to get the computer to offer advice based on something other than a random choice. To do that we will make use of the If statement as well as the elif and else parts of it.

It is important to get a grasp of this as it is used everywhere, across all languages. So, grab a coffee sign up to the subscribe box to the right and let’s get started. You can watch the video, or follow the text. Oh, and you can find the code example here: Tutorial 7 -If Elif Else Example

Once you have opened the Python IDLE GUI and started a new file, we’ll get started by importing the random class and rolling the dice. We do that with the following code… Continue reading

Learning Python, Tutorial 6: User Input

At some point in our programs, we will probably want to get some input from a user. Perhaps their name for example, or their favourite number.

Lets have a look at how to ask the user for that input, using the raw_input() function, and what to do with it once we have it. As ever, you can watch the video, or follow along with this post. The source code can be found here: Tutorial 6 -User Input Example.

Begin by opening your Python IDLE GUI and starting a new file.

There are a couple of ways we can get input from our user, but for the moment we are going to concentrate on a function called raw_input(). This function displays a prompt to the user and converts whatever they put into it into a string. Lets see it in action… Continue reading

Learning Python, Tutorial 5: Random Things

In this Python tutorial, we are going to be having a look at random numbers and making random choices. As usual, you can follow along with the text on this page, or with the video below.

You can find the source code by here: Tutorial 5-Randon Numbers and Strings Example

Let’s start by opening the Python IDLE GUI and then clicking File\New File

Once you have a new window we will type some code to import the random class like so… Continue reading

Learning Python, Tutorial 4: Simple Numbers

I hope you enjoyed the previous tutorial about strings.  In this one, one are going to have a look at numbers.  Don’t worry, I’ll keep it light and we won’t do anything deep.  There is plenty of time for that in later lessons.

As usual, you can follow along with the text, or with the video below.  You can grab the code for this tutorial here: Tutorial 4 – Simple Numbers Example.

Open the Python IDLE GUI (see Tutorial 1 if you need to refresh your memory). Now let’s start by typing some simple sums directly into the GUI window. Enter each of the following followed by the Enter key…

2+10
3*3
10/3
Continue reading

Learning Python, Tutorial 3: Playing with Strings

We have already seen how to print strings to the screen in the last tutorial, but there are a few things that could trip you up, so lets have a look at some common ones here.

You can follow along with the post, or watch the video below.  The code for the tutorial is available here.

We know that we can use code like:

print "Brian said - Leave me alone" Continue reading

Learning Python, Tutorial 2: Hello World and Beyond

In programming tutorials, it is traditional to start with what is called a hello world program.  However, we already did something similar in Tutorial 1 when we printed the result of 10 + 10.  Anyway, I already think that you are better than that, so lets try taking it a step further.

You can follow along with the post, or watch the video below.  The code example is available here.

First we need to open our IDLE Python GUI, do that by going to Start, All Programs, Python 2.7 and clicking on IDLE (Python GUI). Continue reading

Learning Python, Tutorial 1: Install Python

Thanks for joining me on this adventure in learning Python.  Before we can get stuck into some coding, we are going to need to get the Python tools set up on our computer.

You can either follow along with the post here, or watch the video below.  Whichever method you decide on, please do the installation, because we will be needing it in the next tutorial.

It’s simple and free to install.  Start by going to the Python.org download page. Continue reading