Home > Software engineering >  How do you iterate by increasing odd numbers?
How do you iterate by increasing odd numbers?

Time:03-02

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

CodePudding user response:

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

CodePudding user response:

One way to generate odd numbers is to use the 3-argument form of range():

start = 370

for number in range(1, 2*73   1, 2):
    start  = number
    print(start)

Gives:

371
374
379
...
5411
5554
5699
  • Related