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 iterate by increasing odd numbers?

start = 370

for number in range(73):
    print(f"{number+1}. {(start)}")
    start = start * 1 +1

I am trying to add by increasing odd numbers (1,3,5,7,9, etc.).
I am starting out with 370, 371, 374….
I want the output to last until the 73rd term

>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

The formula for odd numbers is 2n + 1, so replace start = start * 1 +1 with:

start += 2*number + 1

First 5 outputs:

1. 370
2. 371
3. 374
4. 379
5. 386
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