Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def cut_in_half(word: str):
- word_half = len(word) // 2
- first_half = word[:word_half]
- second_half = word[word_half:]
- first_half_count = {}
- second_half_count = {}
- for j in first_half:
- if j not in first_half_count.keys():
- first_half_count[j] = 0
- first_half_count[j] += 1
- for j in second_half:
- if j not in second_half_count.keys():
- second_half_count[j] = 0
- second_half_count[j] += 1
- is_jackpot = False
- symbol = ''
- match_len = 0
- for k, v in first_half_count.items():
- if k in "@#$^":
- for x, y in second_half_count.items():
- if k == x:
- if 5 < v < 11:
- if y == 10:
- is_jackpot = True
- symbol = k
- match_len = min(v, y)
- if is_jackpot:
- return [symbol, match_len, "jackpot"]
- elif 6 <= match_len <= 9:
- return [symbol, match_len]
- else:
- return None
- tickets = input().split(", ")
- for ticket in tickets:
- ticket = ticket.rstrip().lstrip()
- if len(ticket) == 20:
- match = False
- for i in ticket:
- if i in "@#$^":
- match = True
- break
- if not match:
- print(f'ticket "{ticket}" - no match')
- else:
- res = cut_in_half(ticket)
- if res is not None:
- length = res[1]
- match_symbol = res[0]
- if len(res) == 3:
- print(f'ticket "{ticket}" - {length}{match_symbol} Jackpot!')
- elif len(res) == 2:
- print(f'ticket "{ticket}" - {length}{match_symbol}')
- else:
- print(f'ticket "{ticket}" - no match')
- else:
- print("invalid ticket")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement