7_3_1

WHAT: Use sequences in programs

HOW:

Activity 1 - READ

I am really hoping that you can still tell me what an Algorithm is. Can you? If not, re-visit this page.

Sequences are just instructions that are placed in the correct order to carry out a task.

Let's try a sequence now:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34

What instructions could be creating this sequence?

Can you work it out? Look here if you need some help.

Activity 2

Try this Python code (see Textbook Kit List for instructions on getting Python):

print (0)
print (1)
print (1)
print (2)
print (3)
print (5)
print (8)
print (13)
print (21)
print (34)

You can watch this video clip to see how to get this code into Python and get it working:

Activity 3 - Pause a minute!

If this is your first time using Python it is a good idea to just stop here and familiarise yourself with opening a new file, saving the file and running the code. TIP: Ctrl + S will save and F5 will run, this will save you a lot of time in the future if you learn and use this from the start.

Activity 4

OK, back to the outcome...

If you managed to get that working then you just used a sequence in a program. The sequence is very simple right now but that's okay.

You just used something called a "print function" to display output on a screen. You can use the print function to print text (or string) on the screen as well.

Add a heading to your Fibonacci Sequence that says what the numbers represent. Make sure that you put your heading in the right place!!

Hint:

print ("Fibonacci Sequence")

Activity 5

Can you spot the difference between printing string and a whole number (integer)?

What is missing when we print an integer compared to printing string?

Activity 6

Save your current Python file and open a new one.

Try this line of code and run it, see what happens:

print ("1")

Now add this line of code and run it:

print (Fibonacci Sequence)

What happens when you run it (see below)?

It works when you print an integer in speech marks but not when you print a string without speech marks!

Activity 7 - READ

When you enter something in speech marks inside a print function, Python will see this as string.

When you enter an integer without speech marks, Python will see this as an integer.

When you enter a word inside a print function, Python tries to look for a variable (or something else). In this case it caused two errors because we haven't learnt about variables yet!

Error 1 - variables can't have spaces in their names

Error 2 - variables must be assigned before they are used

Activity 8

Thinking about what you have just read, create your own simple sequence in Python. Ideas for this could be:

  • A poem
  • A short story
  • Instructions for an action (how to get on a scooter and make it move)
  • A different number sequence that you know from your maths lessons

CHECK:

EMBED:

Option One

Try to figure out how to create the sequence in Activity 8 in Scratch (see textbook kit list).

Option Two

Using your knowledge of the Fibonacci Sequence, try to use maths in Python instead of simply writing the numbers.

Hint: print (1+1) will output the number 2 on the screen.

CLASSROOM IDEAS:

Students should already have a good concept of what a sequence is before starting this learning outcome. You may wish to refresh with them before starting to code sequences on the computer. Scratch or Python can be used here - or another programming language if that's what you prefer!!

What you are focusing on here is - can the students write a sequence of code that performs a task in the correct order?

ScratchEd has a great selection of printable scratch blocks: http://scratched.gse.harvard.edu/resources/vector-scratch-blocks

These could be used to create large copies of a sequence that students need to place in the correct order by physically moving them around on a table or floor. You can even use a whiteboard pen to add variable amounts in later on.

You could use this idea with Python code too!