0% found this document useful (0 votes)
29 views78 pages

Year 8 Computing Programming (Revision)

This document serves as an internal guide for BIS students on the fundamentals of programming, covering key concepts such as algorithms, programming languages, variables, and error checking. It introduces both text-based and visual programming languages, including Python and Scratch, and discusses the importance of pseudocode and subprograms. Additionally, it explains modeling, simulation, and the use of Integrated Development Environments (IDEs) for programming tasks.

Uploaded by

aungheinjerry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views78 pages

Year 8 Computing Programming (Revision)

This document serves as an internal guide for BIS students on the fundamentals of programming, covering key concepts such as algorithms, programming languages, variables, and error checking. It introduces both text-based and visual programming languages, including Python and Scratch, and discusses the importance of pseudocode and subprograms. Additionally, it explains modeling, simulation, and the use of Integrated Development Environments (IDEs) for programming tasks.

Uploaded by

aungheinjerry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 78

Revision

Introduction to Programming

Computing

This document is intended to use internally for BIS


students and should not be shared outside BIS.
Year (8)
Computing
Computers don’t think; they just follow instructions.

Learning to write programs means understanding


algorithms and the different types of programs
they can create.
Year (8)
Computing
Introduction to Programming
 Algorithms is a step-by step sequence of events or
instructions, used to carry out a task or to solve a
problem.
 Algorithms form the basics of
all programming.
 The order in which an
algorithm us carried out is
known as the sequence.
Year (8)
Computing
Introduction to Programming
Turn the following instructions into simple
algorithms.
Walk forward three steps, then turn to your right, wait
for five seconds and then walk backward five steps.

Forward 3 steps.
Turn right 90 degrees.
Wait 5 seconds.
Backward 5 steps.
Year (8)
Computing
Introduction to Programming
 A sequence of instructions to create the 2D
rectangle:
1. Move 40 steps
2. Turn clockwise 90 degrees
3. Move forward 20 steps
4. Turn clockwise 90 degrees
5. Move forward 40 steps
6. Turn clockwise 90 degrees
7. Move forward 20 steps
Year (8)
Computing
Programming Language
 Text-based Language includes keywords for
specific task and can process data in a variety of
formats.
 Examples:
• Python, Java, C++
Year (8)
Computing
Programming Language
 Visual Language graphical blocks are used to
represent coding tasks.
 The blocks are linked together to create an
algorithm.
 Algorithm can be drawn as a
flowchart or created using a
software application.
Year (8)
Computing
Python programming
 A popular text-based programming language.
 Free to download and use, with no restrictions

 It can be run on a wide variety of devices


 From Google to Netflix, it is used in their systems.
Year (8)
Computing
Scratch programming
 A visual coding application that uses colourful
blocks.
 Giving instructions to animate on-screen
characters (sprites)
 Creating simple games and quizzes
 Editing many programs
provided with Scratch to find
out they work
 Sharing programs with other
users around the world
Year (8)
Computing
Variables

 Variables are just things that store information.


 That information is sometimes called data or
values, and, importantly, it can change.
Year (8)
Computing
Three types of Variables
 Strings: Letters or words
 Numbers: any numbers (big numbers, prime
numbers, small numbers, etc.)
 Booleans: True or False (yes or no)
Year (8)
Computing
Simple Python Program
Year (8)
Computing
Sorting Algorithm
 Sorting algorithm reorders a list of values into
the order required (numerical or alphabetical)
Used for:
• High-score tables
in a computer or
smartphone game
• Songs in playlist
• Contacts in phone
• Sales of items in a
shop, sorted by
price or product
Year (8)
Computing
Sorting Algorithm
Year (8)
Computing
Sorting Algorithm
 Sort descending order by reverse = True
Year (8)
Computing
Arithmetic Operators
 Arithmetic operators are used to represent
mathematical functions in programming.
Year (8)
Computing
Pseudocode

 A language that looks


similar to programming
languages, which is used
to quickly design code.
 Programmers use pseudocode to quickly design
code on paper or in a text document.
 They use pseudocode to help them their
algorithms before creating and testing actual code.
Year (8)
Computing
Pseudocode …
• uses simple English terms and syntax that are
easier for people to understand than actual code
• is written one line at a time, like actual code
• is not designed to be actually run on a
computer, so you don’t need to worry about
errors
 There are no fixed rules, but there are guidelines
and commonly used terms
 You can add your shortcuts and terms
Year (8)
Computing
Arithmetic Operators
Python

Scratch
Year (8)
Computing
BIDMAS
 Order of operations when working out a calculation
that has multiple parts
 Brackets, Indices, Division and Multiplication,
Addition and Subtraction
Year (8)
Computing
Relational Operators
 are used to compare two values
Year (8)
Computing
Relational Operators
 Relational operators can be used to create search
parameters
Products Database

Query Example:
SELECT Title FROM Products
Results: All products title
Year (8)
Computing
Relational Operators
Query Example:
SELECT Title FROM Products WHERE Price < 100
Results: Dolphin Lite, Dolphin Lite 2
SELECT Title FROM Products WHERE Type = Laptop
AND WHERE Sold >=50
Results: Dolphin Air

 The database searches use structured query


language (SQL) which is used in design and
website development.
Year (8)
Computing
Relational Operators (Python)

 If statement prints the correct response for True.


 Any other answer, including False will generate
the incorrect response.
Year (8)
Computing
Typical 4-mark Question
You are working as a website developer, creating a
new school login system. You have been asked to
create an algorithm in pseudocode that checks the
strength of a password.
Describe what pseudocode is and how it differs
from a programming language such as Python.
Year (8)
Computing
Typical 4-mark Question
• Pseudocode is similar to programming languages,
which is used to quickly design code. It is written
one line at a time like actual code. It shares
terminology with a variety of real programming
languages. Programmers use pseudocode to plan
programs.
• Pseudocode is different from Python because it
cannot be run on a computer and you don’t need
to worry about syntax errors and finding them in
the code.
Year (8)
Computing
Lesson 6: Variables
A variable is part of a program that needs to be given
a specific value.
Name • Simple, unique within program and not the
same as any program function

arrivalTime Type
• Integer
Value • Float
• Char
• a number, a name, a code or a date • String
• Boolean
• Date
Year (8)
Computing
Lesson 6: Variables in Python
Year (8)
Computing
Lesson 6: Variables in Python
Variables can be used in calculations and the result
can be assigned to a new variable.
Year (8)
Computing
Lesson 7: Sequence, selection and iteration
A sequence is a step-by-step series of instructions
that follow each other in a logical order.
Year (8)
Computing
Lesson 7: Sequence, selection and iteration
Iteration means repeating, or looping, an instruction
until a specified result is reached.
Year (8)
Computing
Lesson 7: Sequence, selection and iteration
Selection is the process of adding a question to an
algorithm and taking action based on the result.
Year (8)
Computing
Lesson 8: Modelling and Simulation
A computer model is a mathematical representation
of a real-life situation.
 It uses past and present data to try to predict what
might happen in the future.
Year (8)
Computing
Lesson 8: Modelling and Simulation
Abstraction is used to remove any unnecessary
information and to focus on the most important
information needed an accurate model.
 If the model is accurate, it
can be used to predict
future or alternative events
by changing variables and
asking ‘what if’ questions.
Year (8)
Computing
Lesson 8: Modelling and Simulation
 Weather and environment
systems: to predict weather
and climate change.

 Finance: to predict currency


rates around the world.
Year (8)
Computing
Lesson 8: Modelling and Simulation
 Astronomy: to predict the movement of planets,
moons, comets and asteroids in our solar system.
 Power generation: to develop new power-
generation systems using renewable and nuclear
energy.
Year (8)
Computing
Lesson 8: Modelling and Simulation

 A computer simulation uses a computer model to


study the behaviour if a real-world system, either
naturally occurring or human-made predications
about future behaviour.
Year (8)
Computing
Lesson 8: Modelling and Simulation

 A simulator is a type of computer model that


allows much more user interactivity.
 Training systems can be designed that use
computer simulations for real-life situations that
might be too dangerous, expensive or difficult for
learners to practice using the real equipment.
Year (8)
Computing
Lesson 8: Modelling and Simulation
 Flight simulator : designed to look and feel as if
you are flying a real aeroplane or spaceship.
Year (8)
Computing
Lesson 8: Modelling and Simulation
 Vehicle simulator : allow you to have the
experience of operating a vehicle, from cars to
tanks to submarines.
Year (8)
Computing
Lesson 8: Modelling and Simulation
 Medical simulator : allow trainee doctors to
practise surgical procedures.
Year (8)
Computing
Lesson 8: Modelling and Simulation
Advantages and disadvantages of computer models
and simulations
Year (8)
Computing
Lesson 9: Error Checking
 Syntax error: a mistake (usually made by the
programmer) within a program that causes the
program to stop running.
 Each programming
language has its
own rules, and a
syntax error breaks
one of these rules.
Year (8)
Computing
Lesson 9: Error Checking
 Spelling name of a function incorrectly
• primt instead of print
 Using an incorrect character
• [] square bracket instead of () round bracket
 Incorrect formatting of a function
• uppercase instead of lowercase
 Incorrect sequencing of a function
• Putting else before if
 Inserting an invalid character
• # symbol into a line
Year (8)
Computing
Lesson 9: Error Checking
The sample code below contains five syntax errors.
Year (8)
Computing
Lesson 9: Error Checking
Errors corrected.
Year (8)
Computing
Lesson 10: Subprogram
 Subprogram is a block of code that can be reused
either within the same program or in several
different programs.
 Using subprogram saves time as you only need to
write the code and check it once.
 You can repeat the subprogram over and over
again.
Year (8)
Computing
Lesson 10: Subprogram
Some uses for subprogram:
 Calculation that needs to run many times
 A password checker that is needed at different
points of the same application
 Inserting the current date and time into a program
 Formatting data into a specific format or print
layout
Year (8)
Computing
Lesson 10: Subprogram
Pre-existing subprograms to perform particular
functions (routines/ procedures):
Year (8)
Computing
Lesson 10: Subprogram
len function returns the number of items in a list or
the number of characters in a string
Year (8)
Computing
Lesson 10: Subprogram
Generating a random number
Year (8)
Computing
Typical 4 – mark exam question
A friend has asked you to look at a short program she
has written. She doesn’t understand why the program
does not work. You have suggested looking for syntax
errors.
Explain the terms syntax error and give two tips for
finding syntax errors.
Year (8)
Computing
Typical 4 – mark exam question
• Syntax errors are errors in a program that break the
rules of the programming language.
• A syntax error stops a particular part of the
program from working such as misspelling the
function print or missing out a bracket. An
incorrect function will halt the program at that
point until the error is resolved.
• Two tips are to check the spelling of all the main
key words and check the layout of functions.
Year (8)
Computing
Part 2: Lesson 1 – IDE
An Integrated Development Environment (IDE) – is
an application designed to help programmers design,
develop and test their programs.
Year (8)
Computing
Part 2: Lesson 1 – IDE
Features

 Code editor – allows to enter code


 Ability to convert code written in one more
programming languages into instructions that a
computer can understand
 Error-checking – tools that highlight syntax errors
and other potential errors as you type
 Virtual testing – window to run the program, do
not have to install program on computer to run it
Year (8)
Computing
Part 2: Lesson 1 – IDE
Advantages
 Share access to a program, work together on the
program and help each other
 Error-checking tools will identify errors in the code
and can resolve them.
 Testing program virtually for errors at an early
stage can solve costly mistake later on.
 Multiple programs can all be managed together in
IDE.
Year (8)
Computing
Part 2: Lesson 1 – IDE
Language Support
 Highlighting or colour codes are used to identify
different types of functions and also highlight
errors.
Year (8)
Computing
Part 2: Lesson 1 – IDE
Language Support
 Autocompletion completes program functions,
and displays advice on available options, as you
type them in.
Year (8)
Computing
Part 2: Lesson 1 – IDE
Language Support
 Auto indentation automatically moves cursor to
the correctly idented position on the next line after
a line of code is entered.
 Syntax checks as you type will spot misspelled
functions or use of an incorrect character or
symbol.
Year (8)
Computing
Part 2: Lesson 2 – Trace Tables
 A trace table is a method of checking an algorithm
line by line and predicting result.
 This then can be used to spot potential errors
when the program is run.
b=a*2

Trace Table
Year (8)
Computing
Part 2: Lesson 2 – Trace Tables
Types of error includes
 Output values that should not appear
 An unintended loop that prevents algorithm
reaching a specified point
PSEUDO Code
Year (8)
Computing
Part 2: Lesson 2 – Trace Tables
IDE Variable Tracing
 To see the values of variables at any point during
the running of a program.
 To highlight errors, and the value of variable at the
point of error is shown.
Year (8)
Computing
Part 2: Lesson 3 – Data Type and Converting
Data Type
Year (8)
Computing
Part 2: Lesson 3 – Data Type and Converting
Converting Data Type
A decimal number has been entered but it needs to
be processed as an integer, with no decimal point.
Year (8)
Computing
Part 2: Lesson 3 – Data Type and Converting
Converting Data Type
Whatever user inputs in Python is automatically a
string. Below program converts input to an integer so
calculation can be carried out using int()
Year (8)
Computing
Part 2: Lesson 3 – Data Type and Converting
Converting Data Type
This program takes a number that has been
calculated in one program and converts it to a string
to become part of a printed statement.
Year (8)
Computing
Part 2: Lesson 4 – String Methods

 A single or a double quote mark can be used to


declare a string.
 Use single quote marks if double quote marks are part
of the string.
Year (8)
Computing
Part 2: Lesson 4 – String Methods
Counting Length of string

Convert to Upper Case


Year (8)
Computing
Part 2: Lesson 4 – String Methods
Counting Lower Case

Counting number of times a specified character


appears in a string
Year (8)
Computing
Part 2: Lesson 4 – String Methods
Counting number of times a specified word
appears in a string

More string methods:


• title() – convert the first letter to upper case
• replace() – replaces one string with another
Year (8)
Computing
Part 2: Lesson 5 – Escape characters and string
slicing
 Escape character – a character or symbol in a string
would normally be interpreted as part of
programming language.
 The character does not appear when program is run.
Inserting \ (backslash) symbol before the symbol
forces the code to accept the symbol is simply part of
the string.
Year (8)
Computing
Part 2: Lesson 5 – Escape characters and string
slicing
 The program identifies a syntax error and will not
run because quotation marks “” are meant for
indicating start and end of a string.
Year (8)
Computing
Part 2: Lesson 5 – Escape characters and string
slicing
 The backslash (/) has been added before each
speech mark that is part of the string.
 Now program accepts that speech marks are part of
the string and runs correctly.
Year (8)
Computing
Part 2: Lesson 5 – Escape characters and string
slicing
 To print block of text correctly, escape characters \t
(tab) and \n (new line) are needed.
Year (8)
Computing
Part 2: Lesson 5 – String slicing
 String slicing is the process of looking at a string as
individual and assigning each an index position.
 This index position can be used to display a
specified range of characters from the string.
Year (8)
Computing
Part 2: Lesson 5 – String slicing
Year (8)
Computing
Typical 4- mark exam question
You have been asked to help build a new school
records system for storing data about all the
students in the school. You are going to be working
with a range of data types.
Explain what is meant by the term data type and
state at least two examples of data types.
Year (8)
Computing

Data types are used to identify any information


stored in a program. It is a classification of data such
as integer, character, etc. The data may be needed to
be used in a calculation or processed as a string.
If the data type is not correctly identified, the data
cannot be processed by the computer.
Two examples of data type are whole number
integers, for example: 3 and Boolean, for example:
Yes or No.

You might also like