Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2021
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. import re
  2.  
  3. count_of_barcodes = int(input())
  4.  
  5. for barcode in range(count_of_barcodes):
  6.     new_barcode = input()
  7.  
  8.     pattern = r'(\@\#+)([A-Z][A-Za-z0-9]{4,}[A-Z]+)(\1)'
  9.     is_valid = re.findall(pattern, new_barcode)
  10.  
  11.     if is_valid:
  12.         product_group = ''
  13.         group = re.findall(r'[0-9]+', is_valid[0][1])
  14.         if group:
  15.             product_group = ''.join(group)
  16.         else:
  17.             product_group = '00'
  18.         print(f'Product group: {product_group}')
  19.     else:
  20.         print('Invalid barcode')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement