Advertisement
simeonshopov

Fancy Barcodes

Apr 5th, 2020
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. #!/usr/local/bin/python3.7
  2. # -*- coding: utf-8 -*import
  3. import re
  4.  
  5. count = int(input())
  6.  
  7. for _ in range(count):
  8.     text = input()
  9.     regex = r'(@[#]+)(?P<barcode>[A-Z]{1}[a-zA-Z0-9]{4,}[A-Z]{1})(@[#]+)'
  10.     match = re.search(regex, text)
  11.     if not match:
  12.         print('Invalid barcode')
  13.     else:
  14.         barcode = match.group('barcode')
  15.         group = ''
  16.         for x in barcode:
  17.             if x.isdigit():
  18.                 group += x
  19.         if group:
  20.             print(f'Product group: {group}')
  21.         else:
  22.             print(f'Product group: 00')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement