Higher – SDD – Reading a file into an array

The code below allows us to read a file into an array then process the data. In this case the processing is just to see how many of each of the numbers (1-6) there were in the file.

def getData(array):
    for x in range(len(array)):
    return array

def countOcc(array,target):
    for number in array:
        if number==target:
    return total

def main():
    dice=[0 for x in range(1000)]
    for x in range(1,7):
        print("Number of",x,"'s=",countOcc(dice,x))

The text file is the result of 1000 D6 rolls.
Can you modify the program to work out which number has the largest number of occurrences?

National 5 – SDD Predefined Functions

So today we were looking over predefined function. For the N5 course we have to be aware of RANDOM, ROUND, & LENGTH.

The RANDOM function picks an integer between two values.

import random
number=random.randint(1,20) # random(StartValue,EndValue)

The ROUND function rounds a real number (floating point) to a fixed number of decimal points.

a=1.2 # 1
b=2.6 # 3
c=2.5 # 2
d=3.5 # 4

print(round(e,2)) # round(valueToRound,NoOfDecimalDigits)

The LENGTH function displays the number of characters in a String or the length of an Array.

name="Stratton was here"

for index in range(len(numbers)):

for index in range(len(name)):


Higher – DIV CSS recap lesson

Using the supplied flag sheet create a HTML document to display each flag. Flags should be created using <DIV>, use CSS to style, you can choose to use inline, internal, or external CSS.

Make use of float, background-color, borders, etc. as you see fit. I would say each flag should be about 300px long and 150px high.

Code for an example French flag shown after the break.

Read more

N5 – CSS locations

There are three places that CSS data can be stored for use with HTML files.


Inline CSS applies to one html element it is added as the value for a style attribute.

<h1 style='color:red;'>Page heading</h1>


Internal CSS is declared inside <style> which is located in the <head> area of the page. It applies to one page of html.

   p {background-color:pink;}



External CSS is stored inside a separate text file (.CSS) it applies to all webpages that link to it (applies to whole site). A link is required in the <head> of the HTML file this link includes the name of the CSS file

  <link rel="stylesheet" type="text/css"  href="style.css">

The CSS file has the selectors and properties stored in the same way as internal

#redBox { background-color:red;

N5 – CSS Selectors

CSS is used to change the look of the website but not the HTML content of the website.

At National 5 there are 3 CSS selectors. These are used to identify which parts of the web page are styled by CSS instructions.

  • Element selector – This is used to select all html elements of the given type.

P {color:red;}

P is the element selector

Color is the CSS property

Red is the CSS value

  • Class selector – this is used to target HTML elements of a given class.

.center {text-align:center;}

.center is the name of the class selector

Text-align is the CSS Property

Center is the CSS Value

  • ID Selector – this is used to target a unique HTML element on the page. NB Only one ID with the same name on a page.

#pageHeading {color:white;}

#pageHeading is the ID selector

Color is the CSS property

White is the CSS value

Logical Operators


Both expressions must be True for the result to be True

Expression 1 Expression 2 Result
False False False
False True False
True False False
True True True



Either expression must be True for the result to be True

Expression 1 Expression 2 Result
False False False
False True True
True False True
True True True



The result is the opposite of the Expression

Expression Result
True False
False True



Problem Solving – Software Development

As you are solving each problem you should be doing the following in your jotter before hitting the computer

Heading – Name of program

Description of problem – pick out the key things the program must do and write it as a paragraph (rewrite the problem in your own words)

  • Analysis
    • Inputs – What the user must enter to the program
    • Processes – What the program does with the inputs to create the outputs
    • Outputs  – What the program display to the user
  • Design (one of the following)
    • Pseudocode – numbered steps that the program follows
    • Structure Diagram
    • Flow Chart