Triangular numbers
Inputs
n is a whole number from 0 to 15.
Your tasks
- Create an empty list
trianglesand a numberrunningthat starts at 0. - Use a loop over the whole numbers 1 up to and including
n. Add the loop number torunning, then add the new value ofrunningtotriangles. - Complete
triangularNumbersso it returnstriangles. Return it, do not print it.
Example
With n = 5, triangularNumbers returns [1, 3, 6, 10, 15].
Rules
- If
nis 0, return an empty list.
Test data
TEST DATA 1: n is 5
TEST DATA 2: n is 0
Practice focus
Loops that count, add up and multiply. Every algorithm starts here: a counter, a total and a stopping point.