Advertisement
horozov86

Final Exam Fundamentals Message Translator

Apr 2nd, 2023
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. import re
  2.  
  3. n = int(input())
  4.  
  5. for _ in range(n):
  6.     text = input()
  7.  
  8.     pattern = r"(!)([A-Z][a-z]{2,})\1:\[([A-Za-z]{8,})\]"
  9.  
  10.     matches = re.findall(pattern, text)
  11.  
  12.     if matches:
  13.         list_numbers = []
  14.         for match in matches:
  15.             command = match[1]
  16.             for letter in match[2]:
  17.                 list_numbers.append(str(ord(letter)))
  18.  
  19.             print(f"{command}: {' '.join(list_numbers)}")
  20.  
  21.     else:
  22.         print("The message is invalid")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement