Question

In Python 3 ,I Need To Get The Following Series Till 'N' Terms-

Posted September 19, 2019 540 views
PythonDevelopment

The Series Is -
1
2 3
4 5 6
7 8 9 10
..............‘N’

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

This should do the trick for you, let me know if I can help explain it further!

counter = 0  # Last number printed
terms = 0  # How many terms were printed last
target = 10  # Change this! How many terms we want to reach

while terms < target:
    terms += 1
    items = []
    for i in range(terms):
        counter += 1
        items.append(counter)
    print(items)  # Output the line, do what you want to make it prettier here
Output
[1] [2, 3] [4, 5, 6] [7, 8, 9, 10] [11, 12, 13, 14, 15] [16, 17, 18, 19, 20, 21] [22, 23, 24, 25, 26, 27, 28] [29, 30, 31, 32, 33, 34, 35, 36] [37, 38, 39, 40, 41, 42, 43, 44, 45] [46, 47, 48, 49, 50, 51, 52, 53, 54, 55]

Hope that helps!
- Matt.

Submit an Answer