Question

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

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


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.