Answer:
def triangular_numbers(n):
triangulars = []
sum = 0
for i in range(1, n+1):
sum += i
triangulars.append(sum)
return triangulars
# Test the function
print(triangular_numbers(5)) # Output: [1, 3, 6, 10, 15]
Step-by-step explanation:
To create a list of the first n triangular numbers, you can use a for loop to iterate from 1 to n, and for each iteration, add the current number to the sum of the previous numbers.
This function will create a list of the first n triangular numbers and return it. You can then assign the returned list to the variable triangulars.