Report this

What is the reason for this report?

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

Posted on September 19, 2019

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



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!

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.

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.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.