Category: Information System Design and Development

Higher – GCHQ’s Christmas Card and RLE

So I was reading the BBC news website which has an article on GCHQ’s Christmas card.

GCHQ

This led me to wonder what is was as I hadn’t seen one before, it turns out it is a nonogram or picross. Then it suddenly hit me, this is a form of run length encoding, that we will be covering later in the course. It’s just that in this case the encoding is only for black squares. Anyway I just wanted to share it now while it was topical.

Python on Raspberry Pi

For a bit of a change the class were programming in Python on a Raspberry Pi.

The program below was used to create a Gold Block in Minecraft.

1
2
3
4
5
6
7
8
from mcpi . minecraft import Minecraft
import mcpi . block as block
mc = Minecraft . create ()
pos = mc. player . getPos ()
x = pos.x
y = pos.y
z = pos.z
mc. setBlock (x, y, z, block . GOLD_BLOCK .id)

Created using http://hilite.me/ and http://www.geocraft.org.uk/

Incrementing Counter

This is a programming statement which increases by a known amount, each time it is called.

  • Score=Score+1
  • One=One+1
  • Bonus=Bonus+10

Incrementing counters are often used inside loops to keep track of the number of iterations.

counter

In the example above the tries=tries+1 line is keeping track of how many times the loop has been iterated.

Python Selection – if:

diceToday we investigated the use of the if statement, this is a selection statement which allows Python to make choices.

We have updated our dice roll program from last time to include a for loop and multiple if statements. The program now displays a summary of the results of 1000 dice rolls.

For homework the class were asked to TRACS the program and we will discuss how efficient it is next time.

3G JPEG Investigation

Today the class carried out an investigation into the JPEG image compression technique.  The pupils were tasked with finding out.

  • Why we use JPEG compression on images?
  • How does JPEG compression work?
  • What is JPEG good at?
  • What is JPEG bad at?
  • When would we use JPEG compression?

The Pupils had to report on a powerpoint slide and include an example of a good and bad use of JPEG.

Read more

Import Function

Python is a general purpose language which means that it can be used to solve many different tasks. However Python does not have a command for every single eventuality. So programmers have created document with lots of different functions, these are called module libraries.

The import command is used to import module libraries into python programs.

dice

The random module stores a number of functions, to get access to the function we want we must first import random then use dot notation to specify the function we want to call. So random.randint calls the randint function from the random module library we imported previously.

There are libraries to do many things and they all should come with documentation to make them easy to use. Like all python programs they are open source so you can have a look inside to see how they work. Here are some example