Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. cnt = 0
  2. wb = load_workbook('zhuk.xlsx')
  3. sheet = wb['Лист5']
  4.  
  5. # Загрузили 1 строчку
  6. prev_line = list()
  7. for cellObj in sheet['B2':'O2']:
  8.     for cell in cellObj:
  9.         prev_line.append(cell.value)
  10.        
  11. # Обработали 1 строчку
  12. check = False
  13. for i in range(len(prev_line)):
  14.     if prev_line[i] == -1 and not check:
  15.         cnt += 1
  16.         prev_line[i] = cnt
  17.         check = True
  18.     elif prev_line[i] == -1 and check:
  19.         prev_line[i] = cnt
  20.     elif prev_line[i] == 0:
  21.         check = False
  22.        
  23. print(prev_line)
  24.  
  25. # Загружаем по 1 строчке, начиная со 2-й
  26. for cellObj in sheet['B3':'O22']:
  27.     line = list()
  28.     for cell in cellObj:
  29.         line.append(cell.value)
  30.        
  31.     # Обрабатываем
  32.     check = False
  33.     for i in range(len(line)):
  34.         if line[i] == -1 and not check and prev_line[i] != 0:
  35.             check = True
  36.             line[i] = prev_line[i]
  37.         elif line[i] == -1 and not check and prev_line[i] == 0:
  38.             check = True
  39.             cnt += 1
  40.             line[i] = cnt
  41.         elif line[i] == -1 and check and prev_line[i] == 0:
  42.             line[i] = line[i - 1]
  43.         elif line[i] == -1 and check and prev_line[i] != 0:
  44.             if prev_line[i] != cnt:
  45.                 cnt -= 1
  46.             line[i] = cnt
  47.         elif line[i] == 0:
  48.             check = False
  49.    
  50.     prev_line = line
  51.     print(line)
  52.    
  53. print('Answer is:', cnt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement