Skip to content

Instantly share code, notes, and snippets.

@codepedia-top
Last active May 8, 2023 08:41
Show Gist options
  • Select an option

  • Save codepedia-top/f7e1cd4bc1ffe7ca9bd831154b049c95 to your computer and use it in GitHub Desktop.

Select an option

Save codepedia-top/f7e1cd4bc1ffe7ca9bd831154b049c95 to your computer and use it in GitHub Desktop.
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