beginner programmer trying to repeat something three times in python

I have to repeat a statement hundreds of times in Excel and am trying to write a super simple script in Python to do this for me, but I can’t figure out how to repeat something 3 times then add to one variable.

Currently I have:

first_well = 2
second_well = 7
third_well = 10

while third_well < 1034:
    print(f'=IF(A{first_well}="","",' + f"IF('Ct RESULTS'!$BE${second_well}=" + f'"yes",IF(DATA_INPUT!$H${third_well}="N/A","0",DATA_INPUT!$H${third_well},""))')
    first_well += 1
    third_well += 1
else:
    print(f'=IF(A{first_well}="","",' + f"IF('Ct RESULTS'!$BE${second_well}=" + f'"yes",IF(DATA_INPUT!$H${third_well}="N/A","0",DATA_INPUT!$H${third_well},""))')
    second_well += 1

Forgive the ugliness of the print statement—it’s going to be put into Excel.

Essentially what I need it to do is print the first statement and increment first_well and third_well on each iteration of the loop, and on every third iteration, print the additional statement and increment second_well.

Answer

Move the logic that’s currently in the else block to inside the while loop but add a conditional so that it only runs on every third iteration of the loop.

For example:

while third_well < 1034:
    print(f'=IF(A{first_well}="","",' + f"IF('Ct RESULTS'!$BE${second_well}=" + f'"yes",IF(DATA_INPUT!$H${third_well}="N/A","0",DATA_INPUT!$H${third_well},""))')
    if third_well % 3 == 0:
        print(f'=IF(A{first_well}="","",' + f"IF('Ct RESULTS'!$BE${second_well}=" + f'"yes",IF(DATA_INPUT!$H${third_well}="N/A","0",DATA_INPUT!$H${third_well},""))')
        second_well += 1
    first_well += 1
    third_well += 1

Note: I also put the conditional part before incrementing third_well so that it’ll run on the third iteration (and every third iteration after that). You can make adjustments to that change (or to the % 3 == 0 part) if you want that part to run, say, on the second iteration and every third after that.