DiYane

Fancy Barcodes

Sep 18th, 2023
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. import re
  2.  
  3. count_of_barcodes = int(input())
  4.  
  5. for value in range(count_of_barcodes):
  6.     barcode = input()
  7.     barcode_pattern = r'\@\#+([A-Z][A-Za-z0-9]{4,}[A-Z])\@\#+'
  8.     is_valid = re.findall(barcode_pattern, barcode)
  9.  
  10.     if is_valid:
  11.         barcode = ''.join(is_valid)
  12.         product_group = ''.join([x for x in barcode if x.isdigit()])
  13.         if not product_group:
  14.             product_group = '00'
  15.         print(f'Product group: {product_group}')
  16.     else:
  17.         print('Invalid barcode')
Tags: python
Add Comment
Please, Sign In to add comment