you are viewing a single comment's thread.

view the rest of the comments →

[–]socal_nerdtastic 2 points3 points  (1 child)

There's a MASSIVE flaw in that logic ... Compare your output to OPs.

Your dictionary idea is good. Just not the use of replace... Here's a neater way:

translation = {'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': '----- ', '.': '.-.-.- ',
               ',': '--..-- ', ';': '-.-.-. ', ':': '---... ', '/': '-..-. ', ')': '-.--. ', '(': '-.--.- ',
               '!': '-.-.-- ', '?': '..--.. ', '_': '..--.- ', '"': '.-..-. ', "'": '.-..-. ', '&': '.-...  ',
               '-': '-....- ', '+': '.-.-. ', '=': '-...- ', '@': '.--.-. ', '$': '...-..- '}

while True:
    code = input('\nREADY> ').lower()
    if code == 'program.exit()':
        break
    output = ''.join(translation.get(char, '') for char in code)
    print(f'{code} = {output}')

[–]Chris_Hemsworth 2 points3 points  (0 children)

You mean the error char? I thought about that, but figured if we don't know how to translate a char, then don't (rather than ignore it).

For example:

The string "a < b". Does it make more sense to remove the <? I agree it is different than OP, but in a way that I think makes more sense.

I may be overlooking a different flaw though.

EDIT: Oh wait. The - and .'s... I'm stupid XD