Advertisement
defbind_

Morse code translator

Aug 25th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. MORSE_CODE_DICT = {'A': '.-', 'B': '-...',
  2.                    'C': '-.-.', 'D': '-..', 'E': '.',
  3.                    'F': '..-.', 'G': '--.', 'H': '....',
  4.                    'I': '..', 'J': '.---', 'K': '-.-',
  5.                    'L': '.-..', 'M': '--', 'N': '-.',
  6.                    'O': '---', 'P': '.--.', 'Q': '--.-',
  7.                    'R': '.-.', 'S': '...', 'T': '-',
  8.                    'U': '..-', 'V': '...-', 'W': '.--',
  9.                    'X': '-..-', 'Y': '-.--', 'Z': '--..',
  10.                    '1': '.----', '2': '..---', '3': '...--',
  11.                    '4': '....-', '5': '.....', '6': '-....',
  12.                    '7': '--...', '8': '---..', '9': '----.',
  13.                    '0': '-----', ', ': '--..--', '.': '.-.-.-',
  14.                    '?': '..--..', '/': '-..-.', '-': '-....-',
  15.                    '(': '-.--.', ')': '-.--.-'}
  16. qd_file = open("morse.txt", "a")
  17.  
  18.  
  19. def encrypt(message):
  20.  cipher = ''
  21.  for letter in message:
  22.   if letter != ' ':
  23.     cipher += MORSE_CODE_DICT[letter] + ' '
  24.   else:
  25.     cipher += ' '
  26.  return cipher
  27.  
  28.  
  29. input_ = input("Input: ").upper()
  30. output = encrypt(input_)
  31. print(encrypt(input_))
  32. qd_file.write(" ( " + input_ + " = " + output + " ) ")
  33. qd_file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement