Matrix Rain

Have we already seen this number? (deja vu again)

8th April 2016

I had a phone interview for a Python job the other day. It started out really well, he was very impressed with my CV and called me a ‘rocket scientist’. But then we got down to the technical questions and my brain decided to go out to lunch, and (yet again) I managed to snatch defeat […]

Hello, Python!

Hello World 2, in Python 3

24th March 2016

Hello World is the famous minimal introductory program for many programming languages. But as soon as it’s served its purpose, it’s discarded in the dust of history for more exciting things, such as data types or expressions… This is politically incorrect discrimination and must be stopped! This loyal and true didactic program should have the right to […]

Rainbow Flag

Rainbow Flag in Pygame

29th June 2015

This little Pygame program paints the Rainbow Flag, as used by the LGBT movement. It illustrates: Importing the Pygame library RGB colours in hexadecimal Python’s for loop using the enumerate() function Filling a rectangular area in Pygame Updating display with flip() Saving the image

Python3.codes

A Quick Introduction to Python 3 Programming

23rd June 2015

This Quick Introduction to Python 3 aims to teach you just enough Python, so that you can get started in computer programming, and try out some of the example codes on this site! First, you’ll want to install Python 3 or you can use the in-browser Trinket near the bottom of the page – just edit […]

A Fake Circle made of Straight Lines

15th June 2015

Inspired by this post on Reddit, I wrote this little script to do the same thing. The circle is an illusion created by 100 straight-line tangents to an invisible circle. The tangents are created by drawing a chord in a larger concentric circle, and moving it’s endpoints around by equal increments 100 times. The larger […]

Tweetable Python Code Golf

9th June 2015

Code Golf is the amusement of writing as short as possible a program to perform a given task. So for example, if the task is to compute the average of a list of numbers (which could be changed at any moment), you might do this: 140 characters (just by coincidence!), or this: 42 characters. In […]

A Graphical Dice Simulator

31st May 2015

This PyGame program simulates the roll of a die (or dice if you prefer). It’s a fairly simple, straightforward thing to do, though it may be worth noting that the spots display is oh-so-slightly clever. Some spots appear in more than one number, e.g. the middle spot is in all the odd numbers, hence the […]

Editors & IDEs

12th May 2015

A text editor is all very well for simple notes, but for programming the basic text editor will quickly become very tedious. For example, Python uses code indentation to indicate ‘blocks’, using tabs or spaces (4 spaces recommended for each level of indentation). It will help a lot if the editor you use ‘knows’ Python! […]

Jengod at the English language Wikipedia [CC BY 2.5 (http://creativecommons.org/licenses/by/2.5), GFDL (www.gnu.org/copyleft/fdl.html) or CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/)], via Wikimedia Commons

Compute Average Heights

3rd May 2015

This is a simple program to compute average heights. In a loop, it prompts the user for heights, inputs a text string and converts it to a ‘real’ number, sums them, and divides by the number of heights. Exit is signalled by negative height, after which the sum of the numbers is divided by the number of […]

Turtle Star

18th April 2015

A very simple Turtle program. Turtle can draw intricate shapes using programs that repeat simple moves. Turtle graphics is a popular way for introducing programming to kids. It was part of the original Logo programming language developed by Wally Feurzig and Seymour Papert in 1966. Imagine a robotic turtle starting at (0, 0) in the […]

Square Spiral

18th April 2015

This is a very simple introduction to Turtle graphics. The turtle starts in the middle of the window, moves forward a small distance, turns right, moves forward a slightly longer distance, right again, even further this time… until the distance equals or exceeds a given limit. Turtle graphics is a popular way for introducing programming […]