Vous êtes sur la page 1sur 31

Programming for Teachers asurrall@thecooperschool.co.

uk
Session Objectives
Understand the constructs that underpin most
programming languages.
Use these constructs to create simple computer
programs using Python.
Programming for Teachers asurrall@thecooperschool.co.uk
About me
Alistair Surrall
CAS Master Teacher
BSc (Hons) Computer Science
MA Technology and Education
Teaching ICT\Computing for 5 years
Leader of Learning with New Technologies at TCS
asurrall@thecooperschool.co.uk

@surrall
Programming for Teachers asurrall@thecooperschool.co.uk
Hardware and Software
Computer systems are made up of two components
hardware and software.
Hardware Software
Programming for Teachers asurrall@thecooperschool.co.uk
What is programming?
Programming is the process of writing instructions to control
hardware. Creating software.
Programming for Teachers asurrall@thecooperschool.co.uk
Programming languages
The instructions you write need to be in a language the
hardware understands. There are loads of programming
languages each with their own idiosyncrasies.
Programming for Teachers asurrall@thecooperschool.co.uk
Common constructs
Nearly all programming languages provide the same
constructs for you to use to create your programs.
Sequencing
Selection
Iteration
Sub-routines
Variables
Data Structures
Programming for Teachers asurrall@thecooperschool.co.uk
Sequencing
Sequencing means each instruction in the program is
executed once in the order it was given.
Programming for Teachers asurrall@thecooperschool.co.uk
Sequencing
Programming for Teachers asurrall@thecooperschool.co.uk
Selection
Selection means that the computer selects which instruction
to execute next.

This can be based on a condition in the program or on user
input.
Programming for Teachers asurrall@thecooperschool.co.uk
Selection
Programming for Teachers asurrall@thecooperschool.co.uk
Selection: IF ELSE
Programming for Teachers asurrall@thecooperschool.co.uk
Selection: IF , ELSE IF
Programming for Teachers asurrall@thecooperschool.co.uk
Iteration
Iteration just means repetition.

There are many times when you find yourself giving the same
instruction repeatedly.

Iteration is used to tell the computers hardware to follow the
same instruction a number of times.

Programming languages use Loops to repeat an instruction.
Programming for Teachers asurrall@thecooperschool.co.uk
Sequence
Programming for Teachers asurrall@thecooperschool.co.uk
Iteration
Programming for Teachers asurrall@thecooperschool.co.uk
Iteration: FOR loops
FOR Loops repeat an instruction a set number of times.
Programming for Teachers asurrall@thecooperschool.co.uk
Iteration: WHILE loops
WHILE Loops repeat an instruction until a condition is met .
Programming for Teachers asurrall@thecooperschool.co.uk
Sub-routines
When a sequence of instructions is going to be repeated a
number of times at different points in the same program it is
often useful to put them in a separate sub-routine.

The sub-routine can then be called at the relevant points in
the program.

When programming a sub-routine can be defined as a named
block of code that carries out a specific task.
Programming for Teachers asurrall@thecooperschool.co.uk
Sub-routines
Programming for Teachers asurrall@thecooperschool.co.uk
Sub-routines
Programming for Teachers asurrall@thecooperschool.co.uk
Sub-routines: Functions
A Function is a sub-routine that returns a value.
Programming for Teachers asurrall@thecooperschool.co.uk
Sub-routines: Procedures
Procedures are sub-routines that dont return a value. They
can display information to a user but they dont return any
information back to the main program.
Programming for Teachers asurrall@thecooperschool.co.uk
Variables
A variable is a named location in the computers memory that
a programmer can use to store & manipulate data whilst the
program is running.
Programming for Teachers asurrall@thecooperschool.co.uk
Variables
Programming for Teachers asurrall@thecooperschool.co.uk
Data types
When you declare your variable by giving it its name the
computer will want to know what type of data you are going
to store in it Text, Number, Character etc.
Programming for Teachers asurrall@thecooperschool.co.uk
Data Structures
Data Structures are a way of storing or organising information
in your program so that it can be used efficiently.

The most common type of data structure is called an array.
Arrays are just a set of variables of the same type held in rows
and columns.
Programming for Teachers asurrall@thecooperschool.co.uk
Data Structures
Data Structures are a way of storing or organising information
in your program so that it can be used efficiently.

The most common type of data structure is called an array.
Arrays are just a set of variables of the same type held in rows
and columns.
Programming for Teachers asurrall@thecooperschool.co.uk
Data Structures: Arrays
Programming for Teachers asurrall@thecooperschool.co.uk
Data Structures: Elements
Each variable in an array is called an element. Each element
can be accessed by referencing its location in the array.

arrNames[3]

Notice that the elements always begin at 0.


Programming for Teachers asurrall@thecooperschool.co.uk
Questions?
Activities
Programming for Teachers asurrall@thecooperschool.co.uk
Pygame

Vous aimerez peut-être aussi