The profile of coding in school has been raised over the last few years by a combination of increasingly accessible development environments and a government focus that has mandated all students arrive in secondary school having experience of two programming languages such as Python or Scratch.
Gone are the days where complicated syntax rules (like ending every line with a semicolon) turned attempts at writing common sense code into a mission in debugging. Compilers now give precise error feedback and languages even exist with simple syntax and which don’t require a compiler at all.
One such language is Python, downloadable for free at www.python.org. Familiar now to thousands of students beginning secondary school and increasingly popular in computer science courses at GCSE, it is reasonable for teachers to assume that students will have some experience of this language. Even for those that don’t, a few simple commands can open up some powerful opportunities for learning mathematics.
The syntax of a “for” loop is the building block of any work in a sequence and follows a simple pattern:
The variable n is an index that increments by the integer values detailed in the range. In this case the loop will start with n = 1, execute any indented commands written below it, and then loop back to the beginning with n increasing to 2 and so on until the end of the range is reached.
The program above lists the integer values from 1 to 9, the key here being that the loop stops when n gets to 10 without completing a final iteration.
The print command simply outputs the value of n with no adjustment, but standard mathematical operators can be used to create more interesting sequences:
Mathematical Operator

Computer Operator

+

+





x

x

÷

/

It is relatively straightforward at this point to allow students to explore given sequences and try to create programs that will generate them. For example the code above can easily be edited to generate the sequence 3,5,7,9,11…
There are numerous advantages for student learning in this approach. The index i is more concrete when presented in coding terms than the abstract n in an nth term, and students are often more willing to experiment with transient computer code than by doing calculations by hand, trying different approaches until a result is achieved.
Once students are able to generate programs quickly to produce specific linear sequences, they can be guided to record the structural rules they are using and even convert their code to nth terms as a shorthand way of recording the code: the only part that changes is the expression in the print command after all. As with any approach to teaching a topic, more or less scaffolding can be provided depending on the students in the class, so it may be appropriate to choose only sequences with a particular common difference to help students spot the patterns in their code to begin with.
For the more enthusiastic students, complicated sequences involving quadratics or even the Fibonacci sequence can be presented as challenges, allowing students to develop deep structural understanding of how they are generated. Try using coding in class and let us know how you get on!