MCPcopy Create free account
hub / github.com/ndleah/python-mini-project / encode_morse

Function encode_morse

Encode_Morse.py/main.py:1–17  ·  view source on GitHub ↗
(message)

Source from the content-addressed store, hash-verified

1def encode_morse(message):
2 char_to_dots = {
3 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.',
4 'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..',
5 'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.',
6 'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-',
7 'Y': '-.--', 'Z': '--..', ' ': ' ', '0': '-----',
8 '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....',
9 '6': '-....', '7': '--...', '8': '---..', '9': '----.',
10 '&': '.-...', "'": '.----.', '@': '.--.-.', ')': '-.--.-', '(': '-.--.',
11 ':': '---...', ',': '--..--', '=': '-...-', '!': '-.-.--', '.': '.-.-.-',
12 '-': '-....-', '+': '.-.-.', '"': '.-..-.', '?': '..--..', '/': '-..-.'
13 }
14 string=""
15 for x in message:
16 string+=char_to_dots[x.upper()]+' '
17 return string[0:-1]
18#test run
19print("Morse code for Hello World!: ")
20print(encode_morse("Hello World!"))

Callers 1

main.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected