Question: A triangular number is a number that is the sum of the integers from 1 to some integer n. Thus 1 is a triangular number

A triangular number is a number that is the sum of the integers from 1 to some integer n. Thus 1 is a triangular number because it's the sum of the integers from 1 to 1; 6 is a triangular number because it's 1+2+3=6.

Given the non-negative integers m and n (with m < n), create a list of the triangular numbers between (and including) m and n. Thus if m is 3 and n is 20, the list would be: [3, 6, 10, 15]. Associate the list with the variable triangulars

Here is the code thus far, but won't work:

tempTriangulars=[]

accumulatedNum=0

triangulars=[]

for index in range(1, n+1):

accumuatedNum += index

if accumulatedNum <=n:

tempTriangulars.append(accumulatedNum)

else:

break

for index in range(0, len(tempTriangulars)):

if tempTriangulars[index] >= m:

triangulars.append(tempTriangulars[index])

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!