Charles Babbage or ‘Cabbage’, (as many of my students refer to him), spent a considerable amount of his time calculating all sorts of numerical values. This included triangular numbers. He was fascinated with statistics and used information and data to make predictions, calculations and decisions surrounding what might happen. Babbage was so obsessed with this, that he created an engine that would allow him to input a number; the machine would process it and then produce an output. He called it the Difference Engine. This was the beginning of computation even though the machine was only a theoretical model with smaller working example models. A complete working version was never built, but Babbage’s thinking was way ahead of his time.

Babbage spent numerous pain staking years calculating and recording these numbers in books and selling them to engineers, accountants and scientists. What is incredible is that 200 years later, in the present day we can code a simple program that will calculate any number of triangular numbers that you so desire.

I asked my students to think about triangular numbers and how they could work them out, we come up various formulas,

For example to calculate the 10th triangular number, (where zero is the first triangular number)

((The position of the triangular number minus 1) multiplied by 0.5)) multiplied by the position of the triangular number

((n-1)*0.5))*n

Next step was to create a program to test the formulas, using Python,

This was a great exercise to introduce and use the ‘definition’ feature. A definition allows you to create a set of steps or procedures that are called by a single name, for example the formula to calculate the triangular number,

def triangle_value(n):

"Print the Triangular numbers for a given list"

tn1 = (n-1)*0.5

tnf = tn1*n

print tnf

Then the user can call the definition by using the name of it, triangle_ value (insert a number of your choice). It saves time having to type out the formula for every single number that you enter.

The program can then be adapted to add in a pause and use a while statement to count down the triangular numbers from say, 10 to 0.

import time

def triangle_value(n):

"Print the Triangular numbers for a given list"

while n > 0:

tn1 = (n-1)*0.5

tnf = tn1*n

print "The", n, "Triangular number is", tnf

n = n - 1

time.sleep(1)

x = input("Enter how many triangular numbers you want to find?")

triangle_value(x)

Babbage spent numerous pain staking years calculating and recording these numbers in books and selling them to engineers, accountants and scientists. What is incredible is that 200 years later, in the present day we can code a simple program that will calculate any number of triangular numbers that you so desire.

I asked my students to think about triangular numbers and how they could work them out, we come up various formulas,

For example to calculate the 10th triangular number, (where zero is the first triangular number)

((The position of the triangular number minus 1) multiplied by 0.5)) multiplied by the position of the triangular number

((n-1)*0.5))*n

Next step was to create a program to test the formulas, using Python,

This was a great exercise to introduce and use the ‘definition’ feature. A definition allows you to create a set of steps or procedures that are called by a single name, for example the formula to calculate the triangular number,

def triangle_value(n):

"Print the Triangular numbers for a given list"

tn1 = (n-1)*0.5

tnf = tn1*n

print tnf

Then the user can call the definition by using the name of it, triangle_ value (insert a number of your choice). It saves time having to type out the formula for every single number that you enter.

The program can then be adapted to add in a pause and use a while statement to count down the triangular numbers from say, 10 to 0.

import time

def triangle_value(n):

"Print the Triangular numbers for a given list"

while n > 0:

tn1 = (n-1)*0.5

tnf = tn1*n

print "The", n, "Triangular number is", tnf

n = n - 1

time.sleep(1)

x = input("Enter how many triangular numbers you want to find?")

triangle_value(x)

**Download it here**