Advertisement
simeonshopov

Wining Ticket

Feb 14th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. tickets = input()
  2. SYMBOLS = ('@', '#', '$', '^')
  3.  
  4.  
  5. def sanitize(a: str):
  6.         a = a.split(',')
  7.         a = [x.strip() for x in a]
  8.         return a
  9.  
  10.  
  11. def valid_length(b: str):
  12.     return len(b) == 20
  13.  
  14.  
  15. def split(lst: str):
  16.     h1 = lst[:10]
  17.     h2 = lst[10:]
  18.     return h1, h2
  19.  
  20.  
  21. def check_match(h1:str, h2:str):
  22.     found = False
  23.     result = []
  24.     for x in SYMBOLS:
  25.         combination = x * 6
  26.         if combination in h1 and combination in h2:
  27.             win_count = min(h1.count(x), h2.count(x))
  28.             found = True
  29.             result = [x, win_count]
  30.     if found:
  31.         return result
  32.  
  33.  
  34. def win_length(a: str, num: int):
  35.     if num < 10:
  36.         print(f'ticket "{ticket}" - {num}{a}')
  37.     else:
  38.         print(f'ticket "{ticket}" - {num}{a} Jackpot!')
  39.  
  40.  
  41.  
  42. tickets = sanitize(tickets)
  43.  
  44. for ticket in tickets:
  45.     if not valid_length(ticket):
  46.         print('invalid ticket')
  47.     else:
  48.         half_1, half_2 =  split(ticket)
  49.         if not check_match(half_1, half_2):
  50.             print(f'ticket "{ticket}" - no match')
  51.         else:
  52.             symbol, count = check_match(half_1, half_2)
  53.             win_length(symbol, count)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement