R
R
Root12021-07-28 20:33:00
Python
Root1, 2021-07-28 20:33:00

How to write functions to translate to Morse code without using lists, tuples, dictionaries?

How can I rewrite the code to not use lists, tuples, dictionaries to convert to Morse code?

MORSE_DICT = {'0': '-----', '1': '.----', '2': '..---', '3': '...--' ,
'4': '....-', '5': '.....', '6': '-....',
'7': '--...', ' 8': '---..', '9': '----.',
}

def morse_number(numbers):
result = ''
for number in numbers:
if number != ' ':
result += MORSE_DICT [number] + ' '
else:
result += ' '

return result
print(morse_number('005'))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-07-28
@Vindicar

Long if-else chain?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question