Advertisement
viligen

message_translator

Dec 5th, 2021
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. import re
  2.  
  3. pattern = r"!([A-Z][a-z]{2,})!:\[([A-Za-z]{8,})\]"
  4.  
  5. n = int(input())
  6. for _ in range(n):
  7.     text = input()
  8.     match = re.search(pattern, text)
  9.     if not match:
  10.         print("The message is invalid")
  11.     else:
  12.         command = match.group(1)
  13.         string = match.group(2)
  14.         ascii_list = [str(ord(s)) for s in string]
  15.         print(f"{command}: {' '.join(ascii_list)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement