Escolar Documentos
Profissional Documentos
Cultura Documentos
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 !ducation
Teaching "CT#Computing $or % years
&eader o$ &earning 'ith (e' Technologies at TCS
asurrall@thecooperschool.co.uk
@surrall
Programming for Teachers asurrall@thecooperschool.co.uk
Hardware and Software
Computer systems are made up o$ t'o components
hard'are and so$t'are.
Hardware Software
Programming for Teachers asurrall@thecooperschool.co.uk
What is programming
Programming is the process o$ 'riting instructions to control
hard'are. Creating so$t'are.
Programming for Teachers asurrall@thecooperschool.co.uk
Programming languages
The instructions you 'rite need to )e in a language the
hard'are understands. There are loads o$ programming
languages each 'ith their o'n idiosyncrasies.
Programming for Teachers asurrall@thecooperschool.co.uk
Common constructs
!early all programming languages pro*ide the same
constructs $or you to use to create your programs.
Se+uencing
Selection
"teration
Su),routines
-aria)les
.ata Structures
Programming for Teachers asurrall@thecooperschool.co.uk
Se"uencing
Se"uencing means each instruction in the program is
e/ecuted once in the order it 'as gi*en.
Programming for Teachers asurrall@thecooperschool.co.uk
Se"uencing
Programming for Teachers asurrall@thecooperschool.co.uk
Selection
Selection means that the computer selects 'hich instruction
to e/ecute ne/t.
This can )e )ased 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# $% &'S&
Programming for Teachers asurrall@thecooperschool.co.uk
Selection# $% ( &'S& $%
Programming for Teachers asurrall@thecooperschool.co.uk
$teration
$teration 0ust means repetition.
There are many times 'hen you $ind yoursel$ gi*ing the same
instruction repeatedly.
"teration is used to tell the computer1s hard'are to $ollo' the
same instruction a num)er o$ times.
Programming languages use 'oops to repeat an instruction.
Programming for Teachers asurrall@thecooperschool.co.uk
Se"uence
Programming for Teachers asurrall@thecooperschool.co.uk
$teration
Programming for Teachers asurrall@thecooperschool.co.uk
$teration# %O) loops
%O) 'oops repeat an instruction a set num)er o$ times.
Programming for Teachers asurrall@thecooperschool.co.uk
$teration# WH$'& loops
WH$'& 'oops repeat an instruction until a condition is met .
Programming for Teachers asurrall@thecooperschool.co.uk
Sub*routines
2hen a se+uence o$ instructions is going to )e repeated a
num)er o$ times at di$$erent points in the same program it is
o$ten use$ul to put them in a separate su),routine.
The su),routine can then )e called at the rele*ant points in
the program.
2hen programming a su),routine can )e de$ined as +a named
bloc, of code that carries out a specific tas,-.
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# %unctions
A %unction is a su),routine that returns a *alue.
Programming for Teachers asurrall@thecooperschool.co.uk
Sub*routines# Procedures
Procedures are su),routines that don-t return a *alue. They
can display in$ormation to a user )ut they don1t return any
in$ormation )ack to the main program.
Programming for Teachers asurrall@thecooperschool.co.uk
.ariables
A variable is a named location in the computer1s memory that
a programmer can use to store 3 manipulate data 'hilst the
program is running.
Programming for Teachers asurrall@thecooperschool.co.uk
.ariables
Programming for Teachers asurrall@thecooperschool.co.uk
/ata types
2hen you declare your *aria)le )y gi*ing it it1s name the
computer 'ill 'ant to kno' 'hat type o$ data you are going
to store in it Te/t4 (um)er4 Character etc.
Programming for Teachers asurrall@thecooperschool.co.uk
/ata Structures
.ata Structures are a 'ay o$ storing or organising in$ormation
in your program so that it can )e used e$$iciently.
The most common type o$ data structure is called an array.
Arrays are 0ust a set o$ *aria)les o$ the same type held in ro's
and columns.
Programming for Teachers asurrall@thecooperschool.co.uk
/ata Structures
.ata Structures are a 'ay o$ storing or organising in$ormation
in your program so that it can )e used e$$iciently.
The most common type o$ data structure is called an array.
Arrays are 0ust a set o$ *aria)les o$ the same type held in ro's
and columns.
Programming for Teachers asurrall@thecooperschool.co.uk
/ata Structures# Arrays
Programming for Teachers asurrall@thecooperschool.co.uk
/ata Structures# &lements
!ach *aria)le in an array is called an element. !ach element
can )e accessed )y re$erencing it1s location in the array.
arrNames[3]
(otice that the elements always )egin at 5.
Programming for Teachers asurrall@thecooperschool.co.uk
0uestions
Activities
Programming for Teachers asurrall@thecooperschool.co.uk
Pygame