Advertisement
viligen

fancy_barcodes

Nov 22nd, 2021
695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. import re
  2.  
  3. pattern_valid = r"@#+([A-Z][A-Za-z0-9]{4,}[A-Z])@#+"
  4. pattern_digits = r"\d+"
  5.  
  6. count = int(input())
  7.  
  8. for _ in range(count):
  9.     barcode = input()
  10.     valid = re.search(pattern_valid, barcode)
  11.     if not valid:
  12.         print("Invalid barcode")
  13.         continue
  14.     digits_group = re.findall(pattern_digits, valid.group(1))
  15.     if not digits_group:
  16.         print("Product group: 00")
  17.     else:
  18.         print(f"Product group: {''.join(digits_group)}")
  19.  
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement