Question
Please, no spam: This will be for python. A triangular number is a number that is the sum of the integers from 1 to some
Please, no spam:
This will be for python. 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 my code thus far:
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])
_________________________
m=1 and n=1 does not work
m=4 and n=10 does not work
m=5 and n=17 does not work
m=1 and n=20 does not work
What can I get this to be correct?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started