Vous êtes sur la page 1sur 3

Python Workbook (Teacher’s Notes)

These are intended to be a skeleton set of work sessions, where the programming “keys to the kingdom” are
introduced. These are, as Dijkstra (sort of) put it:

Sequence Selection

Entry Entry

Entry Entry

?
Action

Action Action Action Action

Action

Exit Exit

Exit Exit

Iteration (Check - Do) Iteration (Do - Check)

Entry
Entry
Entry Entry

? Action Action

Action Action

Action Action

?
Exit Exit

Exit
Exit

Following are the sessions, which I’ve put together and with which I torment the little ones.. They mix a bit of
text-based programming with simple turtle graphics to break things up; having the main point of developing
the classical IPO pattern of programming.
One day I’ll get around to building this into a work that includes file handling and object-oriented stuff.

Note: The sessions are just a starting point. I’ve found they are handy foundations and lend themselves
to diving into more in-depth work.
Session 01 - Simple Output
Objective: To get students to interact with Python, to produce programs producing basic output, and to
understand basic syntax.
Commentary: There’s a lot going on here. Students should get used to programming in a “two part” sense; building a
program and running the program. The shell is where they see the output of their program. The script
window, where they enter in their statements and save their program.
At this point, the fact that statements can be entered directly into the shell, rather than being solely the
preserve of the main script (program) is ignored. It’s perhaps better left to be introduced as a
debugging tool when working with more complex programs than at the start.
Students WILL make typing/syntax errors. Getting used to the fact that syntax errors will prevent a
program from running is essential.
Design of a program is also explicitly left out at this stage. At this stage there is little if any need for
design thinking. Design is a need when a “certain level” of complexity in a program has been reached.

Session 02 - Variables, Expressions & Calculations


Objective: To introduce variables, expressions and the basics of calculation, and most importantly - sequence.
Commentary: Again there’s a lot going on. Students need to get to grips with what a variable is and the primitive
data types associated with them.
Again, the formal design of a program is left out at this stage. What is introduced is actually,
sequence. That there is at least one correct sequence for a program to be written. Not only but also, the
pattern of initialisation (the initial stored values), processing and in the end output is introduced. The
complicating factor here is that output can be produced “as we go” as opposed to happening in just
one distinct step. It is interesting for this session to see which mode of thinking is the more prevalent
with the students.
Perhaps the best thing to say here is that it is necessary for students to realise that (the IPO) sequence
is critical to programming, and that knowing this will help us make more complicated programs, as
they will see in session 03 when simple input is introduced.

Session 03 - Simple Input / Output


Objective: To introduce the IPO sequence that is so useful in programming.
Commentary: This session extends the ideas introduced in the last session, giving students the IPO sequence.
Apart from introducing input() function, and how it works, is the companion idea of casting (to a
number) so calculations can be performed. The beginnings of the necessity of design are introduced;
by way of more complex programs, and stages of input processing and output.

Session 04 - Turtle Graphics


Objective: To introduce more complex sequential programs, with comments and modules (here turtle) as well.
Commentary: The idea here is to take a break from pure text input/output and introduce graphics in a fairly friendly
manner. The idea of importing pre-built modules is introduced. This leads to more complex sequential
programs that require a modicum of thought and hence design. The idea is to get students convinced
of the need for design for any program that has enough complexity. What “enough” means will
depend to some extent on how obvious the sequence is and where the student is in terms their
understanding of programming. It is also a fairly decent background step to covering repetition as a
control structure.
Also introduced are comments, as a way of identifying distinct sections of code. The hoped for hook
is that it makes the code easier to read!
Note that Python has a number of ways to write Turtle graphics code. The one chosen is just because!
Session 05 - Simple Selection
Objective: To introduce the if statement in all its glory. This is also the point where program design is introduced.
Why? Because students (and programmers) often fail to think through what their code is actually
doing with selection. Introducing design at the first major point of program complexity is prudent.
Commentary: The basic idea is to get students understanding selection using the if statement. However, the key is
designing a solution, not just typing and hoping. Why is program design introduced here? Because
students (and programmers) often fail to think through what their code is actually doing when working
with selection. IPO is comparatively simple, but selection usually can be programmed in a number of
ways. Note that the first example can be re-written in a number of ways. The design as presented is
sequential as opposed to being some form of decision tree.
This session may take a while and the students may have to go through some additional exercises to
really get how selection works and to see the various different ways a successful solution can be built.
However, the choice can be made to go on to the next session where decision trees are covered.

Session 06 - Decision Trees (Complex Selection)


Objective: To look at and build (complex) decision making logic trees.
Commentary: The basic idea is to show what logic or decision trees look like and how they map into program code.
There’s a lot to this and a range of ways a tree can be developed. This can be a bit of bother when
you’re thinking one way and the students are thinking another! Keep this in mind!! There’s plenty of
scope to develop this, something not done in the basic session. Go wild, but not mad with it.
Allowing students to share and discuss the different trees that may arise is perhaps the best outcome
from this look at decision trees. It can be used as a vehicle to introduce the concept of program
efficiency; the number of calculations, decisions etc.

Session 07: Iterative Repetition


Objective: To build an understanding of an iterator-based loop using the for statement. This implicitly includes a
look at ranges, lists and the like; being the main examples of the iterators available in Python.
Commentary: Looking at repetition the easiest to get to grips with is the for statement. Why? It covers iterators! It
also is brilliant for looking at lists and ranges and the like. It also provides a handy opportunity to
have some more fun with turtle graphics.
The other key aspect that is being glanced at is that of control. How a loop is controlled, that it will
exit, that it can exit, and how it loops can all be looked at. This becomes more important when the
while loop is looked at.

Session 08: More Iterative Repetition


Objective: To build an understanding of an iterator-based loop using the while statement, with a narrower focus
on loop control. That a loop can and should exit or finish.
Commentary: Both for and while loops are “check, then do” loops. What needs to be stressed here with the while
loop is that a control (usually a single variable) must be set up, and that it is always going to be able
to exit/terminate/finish.
Also of importance is that a for loop can often (always!?) be modelled using a while loop, as they are
both “check then do” loops.
Also tossed in for good measure is the basic randint method from the random module.

Vous aimerez peut-être aussi