Archive for the ‘racypy2’ Category

Extra stuff for RacyPy2



Pets are easily installed packages for Puppy Linux. Just click the link and choose open with PetGet.





I don’t know a huge amount  about Lua and Ruby, but these websites should get you started.




If you are using RacyPy and need some help with general Puppy Linux stuff, the forum here is great.



Hack your homework: grid multiplication


Hacking your homework is not cheating. To write some code that does what you want, you’ll have to think about the maths (or whatever) very carefully. They say the best way to learn something is to teach it. When you write a program, you are teaching your computer to do something.

This program teaches the computer to use the grid method of multiplication. The key to a good maths homework hack is to get the computer to output the “working out” as well as the answer. Here’s a little screenshot of my program’s output.

As you can see, this program takes two numbers and prints out a little table representing the “grid method” way of doing multiplication and then gives you the answer.

Here’s the first part of the code:

The program starts with the usual comment lines, explaining what we are doing. Then we need to import the “math” module, because we are going to need a new mathematical function: math.pow().

I then define a function. We’ve looked at functions a bit before – by doing it this way, I can separate my numbers into hundreds, tens and units just by calling: split().

I create an empty list: grid, into which I can put the values I create. I also initialize a couple of variables, j  and k. The loop that follows is actually the most fun part of the program. I was wondering how to separate out the hundred, tens, units and so on. This is how I did it. If you can think of a simpler way, please let me know.

The loop basically takes the number and divides it by increasing powers of 10 (ie 10, 100, 1000 etc.). This is why we needed the maths module. To raise a number to a power, we need to use math.pow(). For instance if we want to square 3, we would call math.pow(3,2). Here we are using powers of 10. 10 to the power 1 is 10, squared it’s 100 and so on.

The modulus of each of these divisions gets put in “y” to start with. For instance if your number is 14, the remainder when you divide by 10 is 4 – in other words the unit part of the number. If the result is not zero, we add it to the list (we don’t want to bother with the zeros – if you multiply by 1024, for instance, you can ignore the zero for the purposes of your grid). Next I take the y away from x, because I don’t need to worry about that number any more – it’s safely stored in my list. We add one to k, so that next time through the loop we will be using the next power of 10. Finally we divide x by that next power – if the answer is zero, there’s nothing else to do and the while loop will stop.

At the end of the loop I sort the numbers in descending order and send the list “grid” back to the main part of the program.

Here’s the next part:

That’s the hardest bit done. The main part of the program gets the two numbers, sends them off to split() and stores the lists that are produced.

The next bit prints the top line of our table. I’ve made the column-width 7 – you’ll need to alter this if you are working with bigger numbers.  I use a “for” loop to print all the numbers in the first list. I have used “repr” here. This is a bit like “str” – it converts a number into a human-readable form. It also takes the method “.rjust(x)” which right-justifies the value in a column of width “x”.

The next bit is simple too – there’s a nested loop which goes through all the numbers in both lists, multiplies them and prints them. I used “col” to collect the sum of these numbers for the “totals” column and “ans” to keep a running total of that column.

The final line prints the result.

At the moment this program only deals with integers. If you have to use the grid multiplication method for floating point numbers, you could modify this program to deal with that. (Hint: 10 to the power -1 = 0.1).

happy coding!


While you wait for your Raspberry Pi, why not use RacyPy2?


How to use RacyPy or WaryPy.

1. Download the .iso.

2. Download and install DVD Decrypter (or use you favourite .iso burning software).

3. Right click on the .iso file and choose “Burn with DVD Decrypter.

4. Reboot your PC. It should boot from the CD, if it doesn’t do this by default, look for a message telling you what to press for boot options (often F2 or F9).

5. That’s it.


To run WaryPy in Virtual Box.

1. Download WaryPy.vdi.

2. Download and install VirtualBox.

3. Start VirtualBox. Choose “new”.

4. Follow the instructions on screen and choose “Linux” and Linux 2.6.

5. Choose “use existing hard disk” and find the .vdi file.

6. Start your new virtual machine.


Since Liz posted on the RPi homepage about this LiveCD, I’ve had a lot of hits on the blog. Quite a few people have asked about running Puppy in VirtualBox. This works really nicely and I have uploaded a .vdi file for WaryPy (this seems to be better for VB as it doesn’t need PAE).

The .iso of RacyPy is  here.

This Operating System is aimed at people with no experience of using Linux. If you are excited about the Raspberry Pi and keen to start learning to program, this could be useful to you.


1. The original version only came with Python 3 and Pygame. This one has Python 2.7.2 and 3.1.4. Both have Pygame installed which means you are ready to start learning to code whichever version you favour.

2. On the old version I had added a lot of tutorials for several programming languages. This time I have decided to keep it simple. There are lots of great materials for learning Python (you’ll find them in an archive file in my-documents). I’ve left out the others, becuase I am sure that those who want to try other programming languages will have no difficulty finding them.

3. I have included the Java Development Kit (1.7.2). This means that if you wan to learn Java too, you can compile and run Java code without needing to install anything.

4. Typing tutorial included. The nice “gtypist” program is installed, because good coding requires typing skills!

As before, there’s no need to install anything – you just put the disc in your optical drive and boot from it. You can save your work to a memory stick or onto the hard drive without doing anything at all to your existing operating system. If you want to install it, there’s lots of help on the Puppy forum.

As before, this OS is based on Racy Puppy. Racy has a very up-to-date Linux kernel. But it’s a lightweight distribution that should run nicely on quite old machines (eg it’s fine on my old Toshiba laptop with a Pentium 3 processor and 256mb of RAM). If there’s an old computer in your house that no-one uses any more, you will probably find that RacyPy runs really well on it. So you can use this system while we wait for our RPis to be delivered!

happy coding


BugFix (if you haven’t got the latest version).

You may notice that Java isn’t working in Seamonkey. To fix it, click on this link and choose open with petget. I put the wrong link in the plugins folder – oops!

Why should I try Puppy Linux?


I am not going to try to convince you to give up on Windows or Mac Operating Systems, I just wanted to do a post about my favourite Linux distribution: Puppy Linux.

Here are some of the reasons why it is worth learning how to use Linux.

1. The Raspberry Pi will come with a Linux operating system (I think the closest thing to the RPi version is probably this: Fedora Spin LXDE). Since a lot of us may be waiting a while for our Raspberry Pis, why not get used to using Linux while you are waiting?


2. Linux is Open Source. You don’t have to pay for a Linux operating system. You don’t have to pay if you want to upgrade to a newer version. You don’t have to bother with licences, security keys, activation and so on. You are in control of what happens on your machine. Also we have this lovely mascot, Tux!

3. Linux is much less vulnerable to viruses.

4. Linux file-systems don’t fragment as much as Windows – so you don’t need to defragment your hard-drive.

5. Linux systems usually run faster than Windows. This may not be the case if you go for one of the big distributions (like Ubuntu), but if you use a lightweight version (like Puppy), you will find your machine boots and operates much faster.

6. Linux systems can bring old computers back to life. Becuase they are smaller and faster, you can put Linux distros on a machine that couldn’t cope with Windows 7 and find that you can still do all the things you want to do.

7. You can use Linux to rescue your system. If your Windows machine won’t boot and you can’t fix it (or can’t wait for someone else to) you can still get at all your files. Just boot from a Linux live cd and you can access your data and put it somewhere safe.

8. Linux is easy to use. Some people will tell you that you have to be some kind of computer genius to use Linux. This is not the case. You can use a Linux system and make it work perfectly just by using the point-and-click approach. You don’t need to go near the command line unless you want to …

9. Linux has a massive online community of well-informed, helpful, users. I would guess that every Linux distribution has its own forum. People on there will be happy to help you if you do have any problems. For instance, this is the forum for Puppy users.

Well, I hope that you will give Linux a try. In case you missed it, you can find Puppy Linux here.

Or, if you prefer, you can try my remix of Racy Puppy – set up especially for Raspberry Pi fans.


How to do a very simple menu


There are often times when you want to use some form of menu. Here’s one way to do it. First, I make “ans” = True so that it will satisfy the “while” condition. Then the rest of the code is inside the “while” loop. This means that when the user presses enter, “ans” will be false / empty and the program will exit.  Everything else here should be familiar to you, but you may not have seen the use of triple quotations before. We use this in Python to allow us to do multi-line printing. Line returns are allowed so it’s great for this sort of thing and, of course, ASCII art.

Happy Coding,


Hack your homework


Here’s a program that actually does something useful!

When I was learning to program,  I used to enjoy writing code to help me with my homework. This is a program that allows you to input a list of numbers and then shows you the mean, median and mode.

I am publishing this now as it has been hanging around in draft form for ages. I will come back and comment on it in more detail at a later point. Hopefully the comments make it fairly easy to follow. The main thing I was pleased with was how this program shows the use of lists and tuples.


Using turtle graphics


In my post on functions, I used the the example of a little program that draws a square. I didn’t say anything about the “turtle” command. It’s pretty obvious what happens though. When you use this command, Python opens a graphic window and draws things. The idea of turtle graphics began in the Logo programming language in the 1960s. The idea was that there was a virtual “turtle” which you could control with simple commands. If you have used “Scratch”, you have been using a version of Logo. I am going to use this post to review a few of the basics.

Here’s a little Scratch program that draws a square:

It’s not a very good program though. There’s no need for it to be that long, or to repeat itself so much. We can make it more elegant by using a loop.

We’ve done the same thing with 4 lines of code, instead of 9. Another advantage is that if we want to change something (the size of the square for instance), we only need to make the change once. Also, cutting down on repetition of lines of code makes it less likely that we’ll type something in wrong, and easier to put right if we do. Smart programmers are lazy – but in a good way. They write programs that are as simple and elegant as possible.

Okay, this program works, but it’s a bit dull. It just does the same thing every time we run it. But we can change that by using a variable. Let’s switch to Python now.

This is basically the same program I used in the post on functions, but now I have added the use of a variable, so that the program will draw a square the size that the user wants.

But what if I want a triangle or some other shape? Well, we can re-write the program quite simply to make it even more flexible.

Now we have a nice simple program that can draw a very wide range of different shapes. Which is nice 😉

Happy Coding




What is a function? Well, when we tell the Python interpreter:


we are using the function: print().

A function is something the computer knows how to do. We use functions all the time when we are programming.

It’s useful to create our own functions. If there is a specific thing that we need to do quite often in a program, we can define a function that does it. There are several advantages to this. Firstly, we don’t have to type in the code for this operation every time we need to do something. Secondly, if we need to change something about that action, we only need to change it once, in the definition of the function. Here’s an example.

This function just draws a little square. In a program this simple, there isn’t really an advantage in using a function, but as your programs become more complex, you’ll find them very useful. As you can see, we define the function at the start of the of the program. That way, when the computer comes across our call to that funtion, it will know what to do. To define a function we type: “def function_name():” After this comes an indented block of code which is what the computer will do when we call the function. We call the function by entering: “function_name()”.

Just like  with the other functions we have used, we can use the bracketed part of the function call to pass information to the function. Here’s an example:

This time the function is expecting a value – “side”. So if we say “square(50)”, it will draw a square with ides 50 steps long. If we change the “main” part of the program to:

size = int(input(“How long do you want the side to be?”))


the program will ask tell the function to draw a square with lines the length that we specified.

There’s a lot more we can do with function, but hopefully this gives you the basic idea.

Happy Coding


Introducing RacyPy


I am very proud to announce the birth of “RacyPy”. This is a bootable Linux Operating System with Python 3.1.4 and Pygame built in (it’s based on Racy Puppy).

You can download the .iso from here. Edit – better to get the new version – here.

Once you’ve done that, you’ll need to burn the .iso to a cd, using your favourite burning utility.

Then, you can reboot the computer. Many PCs will automatically check for a bootable CD before looking at the hard-drive, but you might have to hit a key to make the computer boot from the CD.

RacyPy will run in RAM and doesn’t do anything to your hard-drive, unless you choose to install it. When you shutdown for the first time, it will ask you to create a save file. You can have this on the hard-drive or somewhere else (eg a memory stick – you’ll need about 512Mb of space).

When you are running RacyPy, you will notice a little snake icon on the desktop. Clicking this will launch the Python IDLE. If you look in “my-documents” you’ll find tutorials for Python and other programming languages.

I hope you will give it a try – it will be a great introduction to working in Linux, as well as helping you to start coding as soon as possible.

The iso is here.

There are additional packages and some discussion over on the Murga Linux forum.

Happy Coding!




If you are new to programming, you will probably enjoy having  go with Scratch.

Scratch is a programming language, but you don’t actually need to write the code. You create a script by arranging a series of commands (you just drag and drop the instructions into a window and arrange them how you like). Then you can run the script and watch the output.

The emphasis is on graphics, sound and cute characters.

This little program gets the cat to draw an octagon and then miaow!

The best thing is to download it and have a play.

It’s here.