SimeonTs

SUPyF2 Text-Pr.-More-Ex. - 04. Morse Code Translator

Oct 27th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. """
  2. Text Processing - More Exercises
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1741#3
  4.  
  5. SUPyF2 Text-Pr.-More-Ex. - 04. Morse Code Translator
  6.  
  7. Problem:
  8. Write a program that translates messages from Morse code to English (capital letters).
  9. Use this page to help you (without the numbers). The words will be separated by a space (' '). There will be a '|'
  10. character which you should replace with ' ' (space).
  11. Example:
  12. Input:
  13. .. | -- .- -.. . |  -.-- --- ..- | .-- .-. .. - . | .- | .-.. --- -. --. | -.-. --- -.. .
  14. Output:
  15. I MADE YOU WRITE A LONG CODE
  16. Input:
  17. .. | .... --- .--. . | -.-- --- ..- | .- .-. . | -. --- - | -- .- -..
  18. Output:
  19. I HOPE YOU ARE NOT MAD
  20.  
  21. #TODO This task is SOLVED, but Judge doesn't support a check with Python for now,
  22. """
  23. morse_code_dict = {'A': '.-', 'B': '-...',
  24.                    'C': '-.-.', 'D': '-..', 'E': '.',
  25.                    'F': '..-.', 'G': '--.', 'H': '....',
  26.                    'I': '..', 'J': '.---', 'K': '-.-',
  27.                    'L': '.-..', 'M': '--', 'N': '-.',
  28.                    'O': '---', 'P': '.--.', 'Q': '--.-',
  29.                    'R': '.-.', 'S': '...', 'T': '-',
  30.                    'U': '..-', 'V': '...-', 'W': '.--',
  31.                    'X': '-..-', 'Y': '-.--', 'Z': '--..',
  32. }
  33. code = input().split()
  34. decrypted_code = ""
  35. for letter in code:
  36.     if letter == "|":
  37.         decrypted_code += " "
  38.     else:
  39.         for key, value in morse_code_dict.items():
  40.             if letter == value:
  41.                 decrypted_code += key
  42. print(decrypted_code)
Add Comment
Please, Sign In to add comment