Discussion about this post

User's avatar
Yuvraj Raghav's avatar

this is my solution:

user_input = input("Enter Text: ")

user_input = user_input.upper().strip()

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': '----.',

'.': '.-.-.-', ',': '--..--', '?': '..--..', '/': '-..-.',

'-': '-....-', '(': '-.--.', ')': '-.--.-', '&': '.-...',

':': '---...', ';': '-.-.-.', '=': '-...-', '+': '.-.-.',

'"': '.-..-.', '$': '...-..-', '!': '-.-.--', '@': '.--.-.'

}

morse_code=[]

for char in user_input:

if char==" ":

morse_code.append('/')

else:

morse_code.append(MORSE_CODE_DICT[char])

print(" ".join(morse_code))

Expand full comment
Bijal's avatar

I reviewed the solution, but I'm not quite sure why .strip() method to print the Morse code in the solution part-1 is necessary. Could you please help clarify it for me?

I checked the output, I didn't saw any difference.

Expand full comment
4 more comments...

No posts