unplugged programming (upl) for teachersispython.com/wp/wp-content/uploads/2014/11/aa_05.9... ·...

19
Page 1 of 19 ispython.com UNPLUGGED PROGRAMMING (UPL) FOR TEACHERS Making, and making sense: hands on, and minds in.” Seymour Papert

Upload: others

Post on 11-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 1 of 19

ispython.com

UNPLUGGED PROGRAMMING (UPL)

FOR TEACHERS “Making, and making sense: hands on, and minds in.” Seymour Papert

Page 2: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 2 of 19

ispython.com

CONTENTS

Introduction ..................................................................................................................... 3

Summary of the Unplugged Course ................................................................................... 4

Worksheet 1: ‘Unplugged’ Programming (UPL) ................................................................. 6

What’s in the Toolbox we will use? ................................................................................... 6

Worksheet 2 Control Structure: Sequence ........................................................................ 7

Worksheet 3: Control Structure: Repetition - Patterns and Symmetry............................. 9

Worksheet 4: The Repeat Control Structure in UPL .......................................................... 9

Worksheet 5: Control Structure : Function ..................................................................... 12

Worksheet 6: Using a Function with a Parameter .......................................................... 14

Worksheet 7: Defining a Function with a Parameter ....................................................... 15

Worksheet 8: Project Program to Draw 3x3 Squares ...................................................... 16

Worksheet 9: Functions to Write Capital Ltters ............................................................. 17

Page 3: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 3 of 19

ispython.com

INTRODUCTION

This is the first part of an exemplar short course for Teachers developed from a CAS Training Course

for Master Teachers delivered at University College London starting September 2014.

The whole course is one of transition, assuming no previous knowledge of Algorithms and

Programming, starting with the same three instructions to drive a pet/robot/sprite/turtle which UPL,

Scratch, Logo and Python all employ. Using an unplugged simplified approach to start frees us to learn

about the art and principles of programming and how to employ some of the fundamental control

structures in our programs, without having to engage with the demands of the computer environment

of a programming language until we are ready. When we are ready, the programs we have written

serve as an already coded pseudo-code and are mapped directly to Scratch 2.0 instructions in a

program. (or Python 3 or Logo if we choose).

We take a project-driven approach to learning in the cross-curricula area of geometric and capital

letter shapes using pattern recognition, symmetry in geometry, and a minimal need for correct syntax,

especially in the oral unplugged version.

The two tasks to be undertaken are:

build a program to draw a 3 x 3 array of squares, see Figure 7.

build programs to draw a (restricted) alphabet of capital letters and write simple words.

These tasks are simplifications or first steps in solving real practical problems. The first problem arose

as a result of wanting to play Sudoku more effectively offline, by simply printing a 9 x 9 array of

squares larger than that offered in newspapers and books. The second arose in an attempt to design

iconic first letters for naming pupils’ work.

Reducing (and hiding) the complexity of a task, by devising a simplified model of a problem, is a

common approach to solving problems and is an example of abstraction and decomposition.

This subsection of the Course has taken shape, and is offered as a fruitful example because different

solutions to these tasks, arrived at by teachers and pupils,

illustrate Computational Thinking in detail,

lend themselves to harnessing three of the five control structures of programming:

sequence, functions and repetition,

enable learning and practice of algorithmic thinking and fundamentals of programming

do without the added distracting complication of handling the pupil-computer interface

at the same time

Page 4: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 4 of 19

ispython.com

make it an effective launch-pad for transition into Scratch 2.0, Logo and Python 3 either

‘unplugged’ or at the Computer interface.

It is intended that this course can be adapted by Teachers to suit their own pupils in the KS1-KS3

range. Throughout the course, the sections prefaced by the diamond bullet point, are specifically

addressed to Teachers.

SUMMARY OF THE UNPLUGGED COURSE

‘Unplugged’ programming is a way to learn how to program, away from the computer. This

course is designed to precede and support learning to program at the computer specifically in

Scratch, Logo and Python, using a single sprite or turtle.

In this worksheet, we introduce the program control structures: sequence, function, and

repetition.

Our aims:

1. To introduce pupils to the art of programming before sitting at a computer.

2. To find a way to support learning about programming, in preparation for and prior to

the other difficulties faced by teachers and pupils when tackling the pupil-computer

interface.

3. To test out how different strategies in Computer Science pedagogy may encourage

creativity, experimentation, discovery, independence, perseverance, learning from

mistakes… and pinpoint Computational Thinking; thus making learning effective,

exciting and enjoyable. (Well, maybe not all at the same time!)

4. There are many thought processes which can be considered to be Computational

Thinking; we will use the following five elements as guidelines to cover the ground. We

are writing/building code which explicitly illustrates how all five elements underpin

learning to program. Both the content and the process are important to understanding.

i. Algorithmic Thinking – thinking through the strategy and steps required to

solve a problem

ii. Decomposition – breaking a problem down into smaller components

iii. Abstraction – reducing complexity by using or creating tools/models iv. Generalization -- adapting solutions so that they can be used to solve a wider

range of problems v. Evaluation – assessing whether a program or technique works correctly,

efficiently and maintains good practice. How the five elements of Computational Thinking underpin the programming process will be addressed in more detail throughout the course. In Seymour Papert’s words: “making and making sense: hands on and minds in”

5. We use our spoken or written program to get an immediate response from our imaginary pet/robot in very much the same way that a Scratch or Python program can drive a sprite or turtle portrayed on the screen. Pupils can work in pairs using UPL (Unplugged Programming Language) in a number of ways. Using the literacy precept “read before you write” we start with:

Page 5: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 5 of 19

ispython.com

a) crack the Code (decomposition). Break down the code of a program into components by using 2 or 3 below in order to get an idea of the whole program.

b) ‘Walk the talk’: one pupil ‘talks’ the instructions, the other ‘walks’ the figure c) ‘Draw the talk’: one pupil ‘talks’ or ‘reads’ the instructions, the other ‘draws’ the

figure d) Later, we use a combination of 2, 3 interactively to construct a program and write

it on paper We need to be on the lookout for patterns of repeated code that help to determine the

physical components of the drawing (decomposition). We start with a few simple instructions/functions, and the idea of a RETURN program to get

our class thinking and programming unplugged. The instructions we use in UPL are all (system) functions standing for quite complex machine code which is hidden away (abstraction). We develop the idea of parameters (generalisation), after we have introduced our own user functions.

As a reinforcement to learning, we can also make use of up1.py, a software tool, which complements the unplugged approach, (download from ispython.com) used to demonstrate the motion of the pet/robot or to ‘crack the code’ by pressing the arrow keys corresponding to the instructions in the program. It’s a way of getting used to the technology that drives a pet/robot/sprite/turtle without having to build a program in Scratch or write a Python program.

This unplugged course in programming serves equally well as a precursor for, or as part of the transition process to programming at the computer --- the pet/robot and its tools matching up exactly with the sprite of Scratch 2.0 and the turtle shared by Logo and Python. You may decide to start up with Scratch 2.0 or Python 3 at any point, but it will save building fairly lengthy programs (Figure 4.) if you introduce sequence, repetition and functions unplugged before moving to the screen.

With the ideas of SPIN(360), pattern, and symmetry we introduce ‘action geometry’, again unplugged, to develop a familiarity with geometrical shapes before moving online with our programming to develop the exciting area of polygons, stars, spirals and irregular shapes to design unique coloured patterns.

Page 6: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 6 of 19

ispython.com

WORKSHEET 1: ‘UNPLUGGED’ PROGRAMMING (UPL)

DEFINITION OF A PET/ROBOT

In UPL (an unplugged programming language, essentially Logo, but adapted for an unplugged

delivery), a pet/robot is defined by 2 characteristics:

Its position -- where it is standing -- if we are ‘walking’ the talk, or a point on the paper -- if we are drawing the path. We start at O (0, 0) the origin, which is usually centre stage/page (squared paper is helpful).

The direction in which it is facing at any moment. (We assume it is facing to the right at the start of each program).

O

Figure 1

WHAT’S IN THE TOOLBOX WE WILL USE?

1. Pet/robot instructions (3): forward (fd); left turn (lt); right turn

(rt).

2. Control structures in UPL (3): sequence, functions and repetition

3. User functions/instructions, tools that we will create to help complete the project (0)

so far

1. THE PET/ROBOT OBEYS JUST 3 INSTRUCTIONS

The instructions given below can be acted out as commands to a pet/robot, where the

pet/robot walks or turns left or right with each command given by a partner. The activities

can all be undertaken in this way and helps to make the process more concrete.

Alternatively the activities can be undertaken in pairs with pencil and (squared) paper.

Choose a name for your pet/robot beginning with a letter from E, F, H, I, L and T. Toby is the name of

our pet turtle. We shall use Toby in our examples.

There are 3 code instructions (in UPL) that the pet/robot obeys:

1. forward1: our pet/robot goes forward 1 step, drawing a trail as it goes. On squared paper

a step is the length of the side of a square. We can make it go forward any number of steps

e.g. forward3: our pet/robot goes forward 3 steps.

Page 7: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 7 of 19

ispython.com

2. left turn: our pet/robot turns left through 90 degrees -- just that, no movement forward

3. right turn: our pet/robot turns right through 90 degrees -- just that, no movement

forward

When we speak the instructions we use the full forms:

forward2, left turn, right turn.

When we write the instructions, for convenience, we shorten the instructions to:

fd2, lt and rt.

We usually write the instructions in a program across the page, although we could write them one below another. Note that our pet/robot starts at O facing to the right .

A program (in UPL) is a set of code instructions taken from the instructions above, which usually gets

the pet/robot to move and draw.

HOW INSTRUCTIONS MATCH UPL IN SCRATCH AND PYTHON

Figure 2

In UPL fd1 means go forward 1 pace. On the screen in Scratch, the 50 steps actually means 50 pixels

which is approximately 0.75 inches. Similarly for Python. So we equate our 1 pace to 50 pixels when

we make the change from UPL to Scratch or Python.

WORKSHEET 2 CONTROL STRUCTURE: SEQUENCE

Sequence is setting up the code instructions in a program, in the right order, usually set out one after the other, reading left to right and top to bottom.

Page 8: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 8 of 19

ispython.com

We are now ready to Crack the code, that is, to figure out what our pet/robot draws when it obeys the code instructions in a program; we will then be in a better position to write code to build our own programs.

Activity 1 Crack the code: If your pet/robot obeys the shortened instructions, reading from left to right in each of the 12 example programs below, what does it draw? (Remember the

pet/robot always starts at O facing right at the beginning of each program).

i. Example: fd3 (in this one instruction program the pet/robot moves three paces to the right.)

ii. lt fd3

iii. lt lt fd3

iv. fd2 lt lt fd2 rt fd3

v. fd2 lt lt fd2 rt fd3 lt lt fd3 lt……………program(1)

vi. fd1 lt fd1 lt lt fd2 lt lt fd1 rt fd1 lt lt fd2 rt fd2

vii. lt lt lt lt……………program(2)

viii. fd2 lt lt fd2 lt lt……………program(3)

ix. fd1 lt lt fd2 lt lt fd1 rt fd2

x. fd1 lt lt fd1 rt fd1 lt lt fd1 rt fd1 lt lt fd1 rt fd1 lt lt

fd1 rt…………..program(4)

xi. fd2 lt fd2 lt fd2 lt fd2 lt……………program(5)

xii. fd1 rt fd1 lt fd1 rt fd1 lt fd1 rt fd1 lt fd1 rt fd1

lt……………program(6)

xiii. Match the programs in ii to xii to drawings (a) to (k)

Figure 3.

Page 9: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 9 of 19

ispython.com

WORKSHEET 3: CONTROL STRUCTURE: REPETITION - PATTERNS AND SYMMETRY

You may have noticed, in the code examples in Activity 1, a number of simple repeat patterns in

sequence. When ‘cracking the code’, it’s a good idea to take note of patterns in the code – they may

reveal important parts of the drawing (decomposition). It sometimes gives us a clue about what the

pet/robot is drawing.

It helps to write the program on separate lines to pick out the pattern. So program (3)

fd2 lt lt fd2 lt lt……………program(3)

we could rewrite as fd2 lt lt

fd2 lt lt……………program(3a)

which shows the pattern repetition and enables us to condense this program into just one instruction

using the repeat structure from our toolbox as follows:

repeat 2[fd2 lt lt]……………program(3b)

In a repeat instruction, the code in the square brackets [ ] is obeyed twice (or as many times as the

number after repeat) in sequence so that program(3), (3a) and (3b) are all equivalent.

Activity 2 i. Find the patterns in the following Activity 1 exercises:

fd1 lt lt fd1 rt fd1 lt lt fd1 rt fd1 lt lt fd1 rt fd1 lt lt

fd1 rt…………..program(4)

fd2 lt fd2 lt fd2 lt fd2 lt……………program(5)

fd1 rt fd1 lt fd1 rt fd1 lt fd1 rt fd1 lt fd1 rt fd1 lt

fd1 rt fd1 lt……………program(6)

ii. Rewrite the programs (4), (5) and (6) to pick out the repeat patterns in the (a) version

as in the example with program(3), (3a).

iii. Shorten the programs into one instruction by using the repeat structure in the (b)

version of each program as in the example with program (3a), (3b).

iv. What does the repeated code represent in the path in each case?

WORKSHEET 4: THE REPEAT CONTROL STRUCTURE IN UPL

fd2 lt lt fd2 rt fd3 lt lt fd3 lt……………program(1)

Page 10: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 10 of 19

ispython.com

lt lt lt lt……………program(2)

repeat 4[lt]……………program(2b)

fd2 lt lt fd2 lt lt……………program(3)

repeat 2[fd2 lt lt]………….program(3b)

fd lt lt fd rt fd lt lt fd rt fd lt lt fd rt fd lt lt fd

rt…………..program(4)

repeat 4[fd lt lt fd rt]…………………program(4b)

fd2 lt fd2 lt fd2 lt fd2 lt……………program(5)

repeat 4[fd2 lt]……………program(5b)

fd1 rt fd1 lt fd1 rt fd1 lt fd1 rt fd1 lt fd1 rt fd1

lt fd1 rt fd1 lt……………program(6)

repeat 5[fd1 rt fd1 lt]……………program(6b)

Figure 4

As you can see from the programs in Figure 3, by using the repeat control structure we are able to

shorten some programs and make it easier to read or “crack the code”.

The shortening of the program is much more noticeable in programming languages like

Scratch and Python where instructions are stacked vertically one below another. For example,

program(4) would occupy 20 lines in both languages, and the equivalent program(4b) would

occupy 7 lines in Scratch, (see Figure 4) and 6 lines in Python. It is why it’s a good idea to learn

to use the repeat structure early on in programming. And one of the reasons why it’s

important to learn about the other control structure in our toolbox: functions.

It would be possible to engage with Scratch and Python at this stage using the repeat structure

in these languages to implement short length, and therefore more workable, programs for

beginners. In Figure 4, we see the equivalent Scratch 2.0 programs for program(4) and (4b)

In the next section, we will see how program (4) can be shortened still further by using the

other tool in our programming toolbox: a simple function.

Page 11: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 11 of 19

ispython.com

Figure 5: program(4)and(4b)in Scratch 2.0 The drawing: a plus sign

Page 12: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 12 of 19

ispython.com

WORKSHEET 5: CONTROL STRUCTURE : FUNCTION

To our tool box, we can add a user function which operates just like an instruction for the pet/robot.

In the ‘staircase’ program(6) below,

fd1 rt fd1 lt fd1 rt fd1 lt fd1 rt fd1 lt fd1 rt fd1

lt fd1 rt fd1 lt……………program(6)

repeat 5[fd1 rt fd1 lt]……………program(6b)

We see how the program is shortened by using the repeat control structure to program(6b). We can

shorten it even more by choosing a function name say stair or st (for short) to replace the code

fd1 rt fd1 lt

We define our function like this:

stair or st is [fd1 rt fd1 lt]……………function(1)

Then we can write program(6) as just one instruction: repeat 5[st]……………program(6c)

We can replace any piece of code in this way. It is often useful when the code is likely to

reoccur in different places in our program or if we want to use the code again in another

program. When we define a function in this way it is a good idea to choose a name that in

some way describes the code hence stair or st in program(6c) where the program

represents a flight of stairs.

However going back to program(4b), which draws the plus sign +, we could define a function

###############

Perhaps a more generally useful building block might be a square:

fd2 lt fd2 lt fd2 lt fd2 lt……………program(5)

repeat 4[fd2 lt]……………program(5b)

Notice that this is a RETURN program which makes it more useful as a building block because we know

it finishes where it starts. Figure 4(a).

We could define a function square or sq (for short) as:

square or sq is repeat 4[fd2 lt]…………function(2)

Notice we could have used program(5) in the definition of square. Because the code of the

body of the function is ‘hidden’ we are not concerned with how the function achieves its aim,

Page 13: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 13 of 19

ispython.com

just so long as it does. We are now going to use sq as an instruction we have made to be

included in our toolbox.

(a) (b) (c) a row Figure 6

Figure 7

Activity 4 Write a program to draw Figure 4(c).

Crack the code:

i. sq lt fd2 lt sq

ii. sq fd2 sq fd2 (Note the extra fd2 after the sq instruction)

iii. Write the program to draw Figure 4(c) using Activity 3 iii.

iv. Simplify your program (if you haven’t already done so) using a repeat

instruction

v. Make your program in Activity 3 iv. into a RETURN program

vi. ** Define a function row as the program you have built in Activity 3 v. and

label it function(3)

vii. *** Using function row, or otherwise, write a program to draw Figure 5.

Page 14: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 14 of 19

ispython.com

WORKSHEET 6: USING A FUNCTION WITH A PARAMETER

Imagine that you wanted to teach your pet/robot to perform a trick (a routine like program (3), for

example) with one simple command – it might turn out to be very useful:

fd1 lt lt fd1 lt lt……………program(3)

Let’s give the routine a simple name that we use as an instruction. Program (2) reminds me of a

‘fetch’ instruction similar to that you might use with a real pet dog. Let’s call it ‘fetch’or fe

anyway.

But we may want to use fetch or fe with its own special meaning with 1, 2, 3 or more, attached,

in the same way as we use forward2 or fd2 to mean 2 paces.

We can decide to use fetch or fe with its own special meaning, in the same way as forward

or fd. Because we are programming unplugged, the next (shaded) section, in which we

formally define the function fetch with its parameter paces, can be omitted at a first

reading.

Activity 5 i. Write the code that fetch3 (or fe3) represents.

Crack the code: What capital letter is this:

ii. fe1 lt fe2 rt……………program(7)

iii. lt fd2 lt fd1 lt lt fe2……………program(8)

iv. lt fe2……………program(9)

v. lt fe2 rt…………….(10)

vi. lt fd1 rt fe1 lt fd1 rt fe1…………….program(11)

Build programs:

vii. Turn program(11) into a RETURN program

viii. Write a program to draw a capital letter E.

ix. Turn your program for E into a RETURN program

Page 15: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 15 of 19

ispython.com

WORKSHEET 7: DEFINING A FUNCTION WITH A PARAMETER

In the same way as the instruction forward1 or fd1, which we have already met, which can

take arguments like 1, 2, 3… paces. We define fetch like this:

fetchpaces or fepaces is [fdpaces lt lt fdpaces lt

lt]…………function(3)

fetch is then said to be a function with a parameter paces, which, when it is used/called in a

program, replaces the parameter paces with 1,2,3 or more, wherever paces occurs in the body of

code in function(3).

so we can now say, for example,

fetch2 or fe2 is to mean fd2 lt lt fd2 lt lt

We put the code that the function name fetch represents inside square brackets to define

and hide it (abstraction) and then use the name fetch, fe, followed by a number (of

paces) as a code instruction or tool, whenever we want.

In fact, fetch or fe which in computing we call a user function, behaves in much the same

way as the instruction fd a pet/robot instruction (and also a system function) in UPL.

fetch, fe, is called a user function or instruction because we built it. forward,

fd, is a system function because it is one of the system tools of UPL.

So in response to the fetch3 instruction the pet/robot goes out 3 paces in a straight line in the

direction in which it is pointing and returns 3 paces to the same point and ends facing in its original

direction. Or for short, if we are writing, we write fe3. After we have defined the function fetch

or fe, we have set up in our toolbox, a new instruction fetch, fe, for our pet/robot where we

vary the number of steps as we like. Both forward and fetch are available us in our toolbox as program

instructions for our pet/robot.

We have brought the pet robot back to O facing and completed a RETURN program. We have seen

the benefit of doing this when drawing a row of squares and an array of squares. We shall use RETURN

programs again when we try to write words with our capital letters. The next Activity may be another

opportunity to use this approach to building blocks.

Page 16: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 16 of 19

ispython.com

WORKSHEET 8: PROJECT PROGRAM TO DRAW 3X3 SQUARES

Activity 6 i. **** Project: Figure 7 can be viewed as a series of horizontal and vertical

intersecting lines. Use this way of looking at the way the drawing is structured

to devise an entirely different algorithm and program for drawing Figure 7.

(algorithmic thinking)

Hint 1: Draw Figure 7 freehand with paper and pencil. How did you do it?

Hint 2: Would you program our pet/robot to draw it the way you did?

Hint 2: You might find fetch3 or fe3 useful in this project.

ii. How would you generalise this project to a 9x9 array of boxes?

Different algorithmic thinking approaches to this project and its generalisations can be

found on: ispython.com/unplugged.

Page 17: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 17 of 19

ispython.com

WORKSHEET 9: FUNCTIONS TO WRITE CAPITAL LTTERS

Using our user function/instruction fe, we are able to shorten appreciably the code which

draws some of the letters, because the pattern that fe stands for can be used as a building

block to draw the letters. We can break some letters down into parts some of which we name

fe1 or fe2. The process of breaking the letter down into parts in this way is called

decomposition. And it is good practice to make user functions for this purpose. But functions

can be used to name, parcel up and hide code of any sort, if doing so can help us. For example,

if we wanted to write words using the capital letters we have drawn, it would be very useful

to have a function which represents the capital letter ‘I’ like this:

icapital or ic (for short), is [lt fe2 rt]……………function(2)

In this case icapital or ic has no number following it (argument); it stands for exactly the

code that is inside the [ ] brackets. The program is a RETURN program. So any time we need

to draw a capital letter ‘I’, our program includes just the instruction ic. That’s a pretty short

program.

Similarly,

tcapital or tc is [lt fd2 lt fe1 lt lt fe1 rt fd2 lt] …………….function(3)

Activity 7

i. lc is [ ]……………function(4)

ii. fc is [ ]

iii. ec is [ ]

iv. hc is [ ]

v. Write a program to write the word ‘IT’.

It will help us to build up words like L I T… when we have gone a bit further in our thinking

and programming, as we shall see.

fd2 lt lt fd2 rt fd3 lt lt fd3 lt……………program(1)

fe1 lt fe2 rt……………program(7)

Figure 3

Page 18: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 18 of 19

ispython.com

Programs (1), (2), (3), (4), (5) and (7) have at least two things in common. The pet/robot ends up where

it started and pointing in the original direction O . We call this a RETURN program. It means that

wherever the pet/robot is on our floor/page, when it obeys a RETURN program, it returns to that

point, facing in the same direction it was facing at the start of the program. For example, program(1)

and program(7) start at O facing right , and draw the letter capital L, and returns to O facing

again. See Figure 4.

Activity 8 x. Write the code that fetch3 (or fe3) represents.

Crack the code: What capital letter is this:

xi. fe1 lt fe2 rt……………program(7)

xii. lt fd2 lt fd1 lt lt fe2……………program(8)

xiii. lt fe2……………program(9)

xiv. lt fe2 rt…………….(10)

xv. Write a program to draw capital letter F with the starting point O at the

bottom of the letter F and facing right .

xvi. Turn your program for F into a RETURN program

We have brought the pet robot back to O facing and completed a RETURN program. We have many

reasons for doing this. We shall see why when we try to write words with our capital letters.

FUNCTIONS TO WRITE CAPITAL LETTERS

Using our user function/instruction fe, we are able to shorten appreciably the code which

draws some of the letters, because the pattern that fe stands for can be used as a building

block to draw the letters. We can break some letters down into parts some of which we name

fe1 or fe2. The process of breaking the letter down into parts in this way is an example of

decomposition. And it is good practice to make user functions for this purpose. But functions

can be used to name, parcel up and hide code of any sort, if doing so can help us. For example,

if we wanted to write words using the capital letters we have drawn, it would be very useful

to have a function which represents the capital letter ‘I’ like this:

icapital or ic (for short), is [lt fe2 lt lt fe2 lt]……………function(2)

In this case icapital or ic has no number following it (argument); it stands for exactly the

code that is inside the [ ] brackets. So any time we need to draw a capital letter ‘I’, our

program includes just the instruction ic. That’s a pretty short program.

Similarly,

tcapital or tc is [lt fe2 lt fd1 lt lt fe2] …………….function(3)

Activity 9

Page 19: UNPLUGGED PROGRAMMING (UPL) FOR TEACHERSispython.com/wp/wp-content/uploads/2014/11/AA_05.9... · This unplugged course in programming serves equally well as a precursor for, or as

Page 19 of 19

ispython.com

Fill in the code for the following capital letters:

i. lc is [ ]……………function(4)

ii. fc is [ ]

iii. ec is [ ]

iv. hc is [ ]

v. Write a program to write the word ‘IT’.

It will help us to build up words like L I T… when we have gone a bit further in our thinking

and programming.

fd2 lt lt fd2 rt fd3 lt lt fd3 lt……………program(1)

fe1 lt fe2 rt……………program(7)

Figure 3.

Programs (1), (2), (3), (4), (5) and (7)have at least two things in common. The pet/robot ends up where

it started and pointing in the original direction O . We call this a RETURN program. It means that

wherever the pet/robot is on our floor/page, when it obeys a RETURN program, it returns to that

point, facing in the same direction it was facing at the start of the program. For example, program(1)

starts at O facing right , and draws the letter capital L, and returns to O facing again. See Figure

4.