Category: Old National 5

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

Python Functions

A function is a predefined block of code which is used then programming. It often contains a number of commands and steps.

Here are some of the functions we have met

print()

This function displays the string that is contained in it parenthesis ().

print(‘Hi there, how are you?)

input()

This function displays the string in its parenthesis but allows the user to enter a string that is then returned and assigned to a variable.

age=input(‘What is your age?’)

str()

Converts the contents of its parenthesis to a string

check=input(‘Is your age ‘+str(age))

len()

Outputs the length (number of characters) of a string or the size (number of elements) in an array

print(‘The length of your name is’,len(name))

float()

Converts a value to a floating point number

weight=float(input(‘How many KG do you weight’))

int()

Converts a value to an integer

age=int(input(‘What is your age?’))

 

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

Python – Input()

Python input() function returns a string to the assigned variable. This can cause us problems when we want to store integers or floats.

We can use the int() function to convert the string to a integer or the float() function to convert it to a floating point. It is better to do this when you get the input or initialise the variable as you may forget later in the program.

InputInt
The first block of code shows Python returning a string. The second block of code uses a int() to return an Integer

 

Evolution of BBC website

bbcOver the years the BBC website has seen a number of changes. These changes were often driven by the rise of new technology.

Take for example the display you are currently viewing this post on. In 1997 the standard PC display was about 1024×768 at best and most people were using SVGA (800×600) as the 14″ CRT screens of the time were a little small. So we moved up to larger CRTs before dropping them and moving to TFTs and introducing widescreen 1920×1080 (1080p).  Laptops brought problems of their own with fiddly input devices and small screens that had large pixels counts.  Then tablets and smart phones brought in touch screens that didn’t have the pixel perfect aim of a mouse.  Faster Internet connections meant that we could start to access and stream audio, then video.

Every time there was an evolution in hardware or software, the site needed to be changed. As well as the hardware changes, society was changing as well. We wanted our information displayed and interacted with in a different way.  This means that the BBC’s site today is quite different from the site that started in 1997.

Take a look at the posts below for more information.