Loop through code with different output
I have a python code which runs through 4 different ranges and provide 4 different output, how do I optimize the code to provide 4 different output (not related) looping through same set of code? E.g. tried code below for workbook in workbooks: wb = load_workbook (os.path.join(path, workbook)) perf_sheet = wb.active rowmax = perf_sheet.max_row y = 22 z = 23 for rows in range (2, rowmax + 1): for col in range(y, z): char = get_column_letter(col) x = (perf_sheet.cell(int(rows), 17)).value if x is not None: if z < 24: (perf_sheet(char + str(rows)]) = len((perf_sheet.cell(int(rows), 17)).value) elif z < 25: (perf_sheet(char + str(rows)]) = x[:1].isnumeric() if z < 26: (perf_sheet [char + str(rows)]) = x[-1:].isnumeric() if z >= 27: break else: (perf_sheet[char+ str(rows)]) = 0