Advertisement
Nenogzar

Untitled

Jan 10th, 2024
1,446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.59 KB | None | 0 0
  1.  
  2. # symbols = {
  3. #     "a": "·-", "b": "-···", "c": "-·-·", "d": "-··", "e": "·", "f": "··-·", "g": "--·", "h": "····", "i": "··",
  4. #     "j": "·---", "k": "-·-", "l": "·-··", "m": "--", "n": "-·", "o": "---", "p": "·--·", "q": "--·-", "r": "·-·",
  5. #     "s": "···", "t": "-", "u": "··-", "v": "···-", "w": "·--", "x": "-··-", "y": "-·--", "z": "--··",
  6. #     "0": "-----", "1": "·----", "2": "··---", "3": "···--", "4": "····-",
  7. #     "5": "·····", "6": "-····", "7": "--···", "8": "---··", "9": "----·",
  8. #     ".": "·-·-·-", ",": "--··--", "?": "··--··", "": "·----·", "!": "-·-·--",
  9. #     "/": "-··-·", "(": "-·--·", ")": "-·--·-", "§": "· ···", ":": "---···",
  10. #     ";": "-·-·-·", "[": "-···-", "..": "-··-·", "-": "-····-", "_": "··-- ·-",
  11. #     "$": "···-··-", "@": "·--·-·", " ": "."
  12. # }
  13. #
  14. # # Taking input from a user
  15. # data = input("Enter text: ").lower()
  16. #
  17. #
  18. # length = len(data)
  19. #
  20. # # Convert to Morse code in list comprehension
  21. # output = [symbols.get(data[i]) for i in range(length) if data[i] in symbols.keys()]
  22. #
  23. # print(' '.join(output))
  24. #
  25.  
  26.  
  27.  
  28. #
  29. MORSE_CODE_DICT = {
  30.     "·-": "a", "-···": "b", "-·-·": "c", "-··": "d", "·": "e", "··-·": "f", "--·": "g", "····": "h",
  31.     "··": "i", "·---": "j", "-·-": "k", "·-··": "l", "--": "m", "-·": "n", "---": "o", "·--·": "p",
  32.     "--·-": "q", "·-·": "r", "···": "s", "-": "t", "··-": "u", "···-": "v", "·--": "w", "-··-": "x",
  33.     "-·--": "y", "--··": "z", "-----": "0", "·----": "1", "··---": "2", "···--": "3", "····-": "4",
  34.     "·····": "5", "-····": "6", "--···": "7", "---··": "8", "----·": "9", "·-·-·-": ".", "--··--": ",",
  35.     "··--··": "?", "·----·": "", "-·-·--": "!", "-··-·": "/", "-·--·": "(", "-·--·-": ")", "· ···": "§",
  36.     "---···": ":", "-·-·-·": ";", "-···-": "[", "-··-·": "..", "-····-": "-", "··-- ·-": "_",
  37.     "···-··-": "$", "·--·-·": "@", ".": " ",
  38.  
  39.  
  40. }
  41.  
  42. def morse_to_text(morse):
  43.  
  44.     text = ""
  45.     symbols = morse.split()
  46.  
  47.     for symbol in symbols:
  48.         if symbol in MORSE_CODE_DICT:
  49.             text += MORSE_CODE_DICT[symbol]
  50.         else:
  51.             print("Невалиден символ на Морз: " + symbol)
  52.             return
  53.     return text
  54.  
  55. morse = input("Въведете текст на Морз, който искате да преведете: ")
  56.  
  57. text = morse_to_text(morse)
  58.  
  59. if text:
  60.     print("Преведеният текст е: " + text)
  61.  
Tags: Morse
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement