ctr = 0 uctr = 0 umax = uctr while True: ctr = ctr + 1 if ctr > 1 and sum([int(i) for i in str(uctr)])%7 == 0: uctr = uctr - 7 else: uctr = uctr + 2 if uctr > umax: umax = uctr print("MAX = ", umax)