Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # symbols = {
- # "a": "·-", "b": "-···", "c": "-·-·", "d": "-··", "e": "·", "f": "··-·", "g": "--·", "h": "····", "i": "··",
- # "j": "·---", "k": "-·-", "l": "·-··", "m": "--", "n": "-·", "o": "---", "p": "·--·", "q": "--·-", "r": "·-·",
- # "s": "···", "t": "-", "u": "··-", "v": "···-", "w": "·--", "x": "-··-", "y": "-·--", "z": "--··",
- # "0": "-----", "1": "·----", "2": "··---", "3": "···--", "4": "····-",
- # "5": "·····", "6": "-····", "7": "--···", "8": "---··", "9": "----·",
- # ".": "·-·-·-", ",": "--··--", "?": "··--··", "": "·----·", "!": "-·-·--",
- # "/": "-··-·", "(": "-·--·", ")": "-·--·-", "§": "· ···", ":": "---···",
- # ";": "-·-·-·", "[": "-···-", "..": "-··-·", "-": "-····-", "_": "··-- ·-",
- # "$": "···-··-", "@": "·--·-·", " ": "."
- # }
- #
- # # Taking input from a user
- # data = input("Enter text: ").lower()
- #
- #
- # length = len(data)
- #
- # # Convert to Morse code in list comprehension
- # output = [symbols.get(data[i]) for i in range(length) if data[i] in symbols.keys()]
- #
- # print(' '.join(output))
- #
- #
- MORSE_CODE_DICT = {
- "·-": "a", "-···": "b", "-·-·": "c", "-··": "d", "·": "e", "··-·": "f", "--·": "g", "····": "h",
- "··": "i", "·---": "j", "-·-": "k", "·-··": "l", "--": "m", "-·": "n", "---": "o", "·--·": "p",
- "--·-": "q", "·-·": "r", "···": "s", "-": "t", "··-": "u", "···-": "v", "·--": "w", "-··-": "x",
- "-·--": "y", "--··": "z", "-----": "0", "·----": "1", "··---": "2", "···--": "3", "····-": "4",
- "·····": "5", "-····": "6", "--···": "7", "---··": "8", "----·": "9", "·-·-·-": ".", "--··--": ",",
- "··--··": "?", "·----·": "", "-·-·--": "!", "-··-·": "/", "-·--·": "(", "-·--·-": ")", "· ···": "§",
- "---···": ":", "-·-·-·": ";", "-···-": "[", "-··-·": "..", "-····-": "-", "··-- ·-": "_",
- "···-··-": "$", "·--·-·": "@", ".": " ",
- }
- def morse_to_text(morse):
- text = ""
- symbols = morse.split()
- for symbol in symbols:
- if symbol in MORSE_CODE_DICT:
- text += MORSE_CODE_DICT[symbol]
- else:
- print("Невалиден символ на Морз: " + symbol)
- return
- return text
- morse = input("Въведете текст на Морз, който искате да преведете: ")
- text = morse_to_text(morse)
- if text:
- print("Преведеният текст е: " + text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement