Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do you label your output of a for loop line by line using numbers?

sqaure = 1
start = 1443

end = start + 96*3 + 1

for number in range(start, end, 3):

    

I want to make the output look like:

  1. 1443
  2. 1446
  3. 1449 etc.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You could use enumerate() to get the first number in your output and then use an f-string to format the output:

for i, number in enumerate(range(start, end, 3), start=1):
    print(f"{i}. {number}")

Output:

1. 1443
2. 1446
3. 1449
4. 1452
5. 1455
6. 1458
7. 1461
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading