L2: Sequence
KS4 - Programming
Starter activity
Think, write, pair, share
Why do we need translators in
programming?
Starter activity
Think, write, pair, share
Computers can only execute machine
code, so translators are required for
executing the programs that programmers
write in high-level languages.
Objectives
Lesson 2: Sequence
In this lesson, you will:
● Describe the tools an IDE provides (editors, error diagnostics, runtime environment,
translators)
● Use subroutines in programs
● Define a sequence as instructions performed in order, with each executed in turn
● Predict the outcome of a sequence and modify it
● Interpret error messages and define error types and identify them in programs (logic,
syntax)
4
Activity 1
Integrated development environments (IDEs)
IDEs were created to give programmers
all the tools they needed to write
programs in one place.
They allow you to write, run, and debug
code without having to switch programs.
They were designed to make
programming easier!
Activity 1
Integrated development environments (IDEs)
Basic text editor
IDEs make it easier to write code because if today_is_cold:
they provide useful tools, like syntax print("Wear a coat")
colour coding.
IDE example
if today_is_cold:
print("Wear a coat")
Activity 1
Integrated development environments (IDEs)
Basic text editor
IDEs can also highlight important syntax
if today_is_cold:
structures to remind you to include them.
print("Wear a coat")
IDE example
if today_is_cold:
print("Wear a coat")
Activity 1
Integrated development environments (IDEs)
Basic text editor
They will often automatically indent
if today_is_cold:
code for you.
print("Wear a coat")
Python is very particular about indents.
The IDE will remind you if it thinks an
indent is required by putting one in for
IDE example
you.
if today_is_cold:
print("Wear a coat")
Activity 1
Integrated development environments (IDEs)
Basic text editor
And they can autocomplete lines of code
if today_is_cold:
that are typically used.
print("Wear a coat")
IDE example
import tim
if today_is_cold:
print("Wear a coat")
Activity 1
Integrated development environments (IDEs)
IDE example
In programming, the language specific
code that you write in has its own syntax. if today_is_cold:
The syntax is unique to that programming print"Wear a coat")
language.
An IDE can point out any syntax errors Error message
that you have made. This means that you line 2
can then check and fix them. print"Wear a coat")
^
SyntaxError: invalid syntax
>>>
Activity 1
Integrated development environments (IDEs)
IDE example
In Python, the IDE will call the
interpreter to translate the code and print("What is your name?")
allow you to run and test your program. name = input()
print("Hello", name)
This means that you can test your code as
you write your program. Runtime output
What is your name?
Becky
Hello Becky
>>>
Activity 1
Integrated development environments (IDEs)
Basic text editor
Without an IDE, you would have to write
if today_is_cold:
all of your programs in a basic text
print("Wear a coat")
editor.
You would then need to switch programs
to translate the code and test it. An IDE
helps programmers because it bundles
together these processes.
Activity 1
Question
How many features of an IDE can you if today_is_cold:
spot in this diagram? print"Wear a coat")
line 2
print"Wear a coat")
^
SyntaxError: invalid syntax
>>>
Activity 1
Question
Syntax colour coding Syntax highlighting
if today_is_cold:
print"Wear a coat")
Automatic indents line 2 Syntax error
print"Wear a coat") checking
^
SyntaxError: invalid syntax
>>>
Activity 2
Introducing your IDE
Here is a demonstration of the IDE that
you will be using for this course.
Activity 2
Your first Python code
1 def welcome(): Use the worksheet to help you write your
2 print("Hello world") first piece of Python code.
3 welcome()
Activity 3
Twinkle, twinkle, little sequence
Precise instructions are very important
when programming. You also need to
make sure that your code is written in the
correct sequence.
A sequence of instructions will be read
from top to bottom, performing each
instruction in turn.
Activity 3
Twinkle, twinkle, little sequence
A karaoke program has been created to
help a class of nursery children remember
the words to Twinkle, Twinkle, Little Star.
You will need to investigate the code to
see how it works, and then modify it so
that it is finished.
Activity 3
Twinkle, twinkle, little sequence
Use the Activity 3 worksheet to help you
do this.
Plenary
Sequences
1 def welcome(): Question .
2 print("Hello world")
You have made a welcome screen for a
3
game. What will appear on screen when
this code executes?
A.
A
Hello world will appear
B
B. “Hello world” will appear
▹ C
C. Nothing
D
D. Welcome will appear
The subroutine has not been called, which means that
nothing will be displayed on the screen
Plenary
Sequences
1 def letterb(): Question .
2 print("b")
What will appear on screen when this
3 def lettera():
code executes?
4 print(“a”)
5
6 lettera() A.
A b followed by a
7 letterb() ▹ B.
B
a followed by b
C.
C
Nothing
D.
D
lettera, letterb
The subroutines have been written in b, a order, but
they have been called in a, b order, so this is when
they will be run
Plenary
Syntax
1 def welcome(): Question .
2 Print("Hello world")
What will happen when this code is
3 welcome()
executed?
▹ A.
A Syntax error on line 2
B.
B
Syntax error on line 3
C.
C
Nothing
D.
D
Hello world will appear
A capital P has been used for the print statement. This
would cause a syntax error.
Homework
Complete your make task
For Activity 3, you were given a make
task to create a karaoke program for your
favourite song.
Complete this for homework.
Due next lesson
Summary
Next lesson
In this lesson, you… Next lesson, you will…
Learnt about the IDE Learn how to use variables within your
programs.
Wrote your first Python programs
Learnt about sequencing
24