Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. import re
  2.  
  3. counts = input()
  4. counts = int(counts)
  5.  
  6.  
  7. def is_valid(barcode):
  8.     if re.search('^@#+([A-Z][a-zA-z0-9]+[A-Z])@#+$', barcode) and '_' not in barcode and (len(barcode.replace('@', '').replace('#', '')) >= 6):
  9.         return True
  10.     else:
  11.         return False
  12.  
  13. while counts > 0:
  14.     barcode = input()
  15.     if is_valid(barcode):
  16.         product_group = ''.join(re.findall('\d+', barcode))
  17.         if len(product_group) == 0:
  18.             product_group = '00'
  19.         print(f"Product group: {product_group}")
  20.     else:
  21.         print('Invalid barcode')
  22.     counts -= 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement