Advertisement
GeorgiLukanov87

10. Winning Ticket , Text Processing - Exercise 100/100

Jul 24th, 2022 (edited)
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.19 KB | None | 0 0
  1. # 10. Winning Ticket , Text Processing - Exercise 100/100
  2. # https://judge.softuni.org/Contests/Compete/Index/1740#9
  3.  
  4.  
  5. def calculate_value(some_side, spec_symbol):
  6.     final_string = 0
  7.     symbol_string = f"{spec_symbol * 6}"
  8.     if symbol_string in some_side:
  9.         final_string = len(symbol_string)
  10.  
  11.     symbol_string = f"{spec_symbol * 7}"
  12.  
  13.     if symbol_string in some_side:
  14.         final_string = len(symbol_string)
  15.  
  16.     symbol_string = f"{spec_symbol * 8}"
  17.  
  18.     if symbol_string in some_side:
  19.         final_string = len(symbol_string)
  20.  
  21.     symbol_string = f"{spec_symbol * 9}"
  22.  
  23.     if symbol_string in some_side:
  24.         final_string = len(symbol_string)
  25.  
  26.     symbol_string = f"{spec_symbol * 10}"
  27.  
  28.     if symbol_string in some_side:
  29.         final_string = len(symbol_string)
  30.  
  31.     return int(final_string)
  32.  
  33.  
  34. def is_ticked_valid(some_ticket):
  35.     if len(some_ticket) == 20:
  36.         return True
  37.     print('invalid ticket')
  38.     return False
  39.  
  40.  
  41. def is_ticked_contain_special_symbols(some_ticket):
  42.     for smbl in some_ticket:
  43.         if smbl in winners_symbols:
  44.             return True
  45.     print(f'ticket "{ticket}" - no match')
  46.     return False
  47.  
  48.  
  49. def symbol_finder(some_ticket):
  50.     for char1 in some_ticket:
  51.         if char1 in winners_symbols:
  52.             searched_symbol = char1
  53.             return searched_symbol
  54.  
  55.  
  56. all_tickets = input().split(',')
  57. winners_symbols = ['@', '#', '$', '^']
  58. start_index = 0
  59. for ticket in all_tickets:
  60.     ticket = ticket.strip()
  61.     if is_ticked_valid(ticket) and is_ticked_contain_special_symbols(ticket):
  62.         matched_symbol = symbol_finder(ticket)
  63.         left_side = ticket[:10]
  64.         right_side = ticket[10:]
  65.         result1 = calculate_value(left_side, matched_symbol)
  66.         result2 = calculate_value(right_side, matched_symbol)
  67.         if result1 >= 6 and result2 >= 6:
  68.             win_value = min(result1, result2)
  69.             if result1 == 10 and result2 == 10:
  70.                 print(f'ticket "{ticket}" - {int(win_value)}{matched_symbol} Jackpot!')
  71.             else:
  72.                 print(f'ticket "{ticket}" - {int(win_value)}{matched_symbol}')
  73.         else:
  74.             print(f'ticket "{ticket}" - no match')
  75.  
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement