Python implementation of the comparison of the completed Morse code translator with sound

From , 3 Years ago, written in Python, viewed 225 times.
URL https://pastebin.vip/view/0912d0f1
  1. import pygame
  2. import time
  3. import sys
  4.  
  5. CODE = {'A': '.-',     'B': '-...',   'C': '-.-.',
  6.         'D': '-..',    'E': '.',      'F': '..-.',
  7.         'G': '--.',    'H': '....',   'I': '..',
  8.         'J': '.---',   'K': '-.-',    'L': '.-..',
  9.         'M': '--',     'N': '-.',     'O': '---',
  10.         'P': '.--.',   'Q': '--.-',   'R': '.-.',
  11.         'S': '...',    'T': '-',      'U': '..-',
  12.         'V': '...-',   'W': '.--',    'X': '-..-',
  13.         'Y': '-.--',   'Z': '--..',
  14.        
  15.         '0': '-----',  '1': '.----',  '2': '..---',
  16.         '3': '...--',  '4': '....-',  '5': '.....',
  17.         '6': '-....',  '7': '--...',  '8': '---..',
  18.         '9': '----.'
  19.         }
  20.        
  21. ONE_UNIT = 0.5
  22. THREE_UNITS = 3 * ONE_UNIT
  23. SEVEN_UNITS = 7 * ONE_UNIT
  24. PATH = 'morse_sound_files/'
  25.  
  26. def verify(string):
  27.         keys = CODE.keys()
  28.         for char in string:
  29.                 if char.upper() not in keys and char != ' ':
  30.                         sys.exit('Error the charcter ' + char + ' cannot be translated to Morse Code')
  31.  
  32. def main():
  33.        
  34.        
  35.         print 'Welcome to Alphabet to Morse Code Translator v.01\n'
  36.        
  37.         msg = raw_input('Enter Message: ')
  38.         verify(msg)
  39.         print
  40.         pygame.init()
  41.        
  42.         for char in msg:
  43.                 if char == ' ':
  44.                         print ' '*7,
  45.                         time.sleep(SEVEN_UNITS)
  46.                 else:
  47.                         print CODE[char.upper()],
  48.                         pygame.mixer.music.load(PATH + char.upper() + '_morse_code.ogg')
  49.                         pygame.mixer.music.play()
  50.                         time.sleep(THREE_UNITS)
  51.                        
  52. if __name__ == "__main__":
  53.         main()
  54.  
  55. #//python/6388

Reply to "Python implementation of the comparison of the completed Morse code translator with sound"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website