from PIL import Image import time i = 1 while True: page = Image.open("split/input%i.jpg"%i) if i % 2 == 0: #check where the for loop is print("trying even") #rotate image by 90 degrees angle = 90 out = page.rotate(angle, expand=True) out.save('rotated/input%i.jpg'%i) print('This is an even page number') time.sleep(2) print("variable i: ", i) else: #check where the for loop is print("trying odd") #rotate image by 90 degrees angle = 270 out = page.rotate(angle, expand=True) out.save('rotated/input%i.jpg'%i) print('This is an odd page number') time.sleep(1) print("variable i: ", i) i+=1