Last active
May 8, 2023 08:41
-
-
Save codepedia-top/f7e1cd4bc1ffe7ca9bd831154b049c95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| codes = { | |
| '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': '--..', | |
| '1': '.----', | |
| '2': '..---', | |
| '3': '...--', | |
| '4': '....-', | |
| '5': '.....', | |
| '6': '-....', | |
| '7': '--...', | |
| '8': '---..', | |
| '9': '----.', | |
| '0': '-----', | |
| '.': '.-.-.-', | |
| ',': '--..--', | |
| '?': '..--..', | |
| '\'': '· − − − − ·', | |
| '!': '− · − · − −', | |
| '/': '− · · − ·', | |
| '(': '− · − − ·', | |
| ')': '− · − − · −', | |
| '&': '· − · · ·', | |
| ':': '− − − · · ·', | |
| ';': '− · − · − ·', | |
| '=': '− · · · −', | |
| '+': '· − · − ·', | |
| '-': '− · · · · −', | |
| '_': '· · − − · −', | |
| '"': '· − · · − ·', | |
| '$': '· · · − · · −', | |
| '@': '· − − · − ·', | |
| } | |
| def to_morse_code(english_plain_text): | |
| morse_code = '' | |
| for char in english_plain_text: | |
| if char == ' ': | |
| morse_code += ' ' | |
| else: | |
| morse_code += codes[char.upper()] + ' ' | |
| return morse_code | |
| morse_code = to_morse_code('codepedia') | |
| print(morse_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment