A triangular number correspond to the number of dots that would appear in an equilateral triangle when using a basic triangular pattern to build the triangule.
The triangular numbers sequence contains all the triangular numbers in order.
The first 10 numbers of the triangular number sequence are:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, …
The following table shows how we can calculate each triangular number from this sequence:
Triangular Number | Calculation |
1 | =1 |
3 | =1+2 |
6 | =1+2+3 |
10 | =1+2+3+4 |
15 | =1+2+3+4+5 |
… | … |
So using an iterative approach in Python we can easily write a script to work out the first 100 triangular numbers:
This short program is a good example of:
Finding the nth term in the sequence
The following mathematical formula can be used to find the nth triangular number in this sequence:
nth term = n(n+1)/2
Other Number Sequences
The following Python challenges will get you to work with different types of number sequences and series:
- Finding the tirst 100 terms of different number sequences.
- Finding the nth term of a number sequence.
- The Collatz Conjecture.
Series vs. Sequence?
Did you know?
The main difference between a series and a sequence is that a series is the sum of the terms of a sequence.
So let’s investigate the following Python challenges based on series:
Extra Challenge
You may also enjoy the following challenge: