Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- pattern = r'[$]{6,10}|[#]{6,10}|[@]{6,10}|[\^]{6,10}'
- tickets = [el.replace(' ', '') for el in input().split(',')]
- for ticket in tickets:
- if not len(ticket) == 20:
- print('invalid ticket')
- else:
- left_half = ticket[:10]
- right_half = ticket[10:]
- left_match = ''.join(re.findall(pattern, left_half))
- right_match = ''.join(re.findall(pattern, right_half))
- num_of_symbols = min(len(left_match), len(right_match))
- if num_of_symbols == 0 or not left_match[:num_of_symbols] == right_match[:num_of_symbols]:
- print(f'ticket "{ticket}" - no match')
- else:
- winning_symbol = left_match[0]
- text_to_print = f'ticket "{ticket}" - {num_of_symbols}{winning_symbol}'
- if num_of_symbols == 10:
- text_to_print += ' Jackpot!'
- print(text_to_print)
Add Comment
Please, Sign In to add comment