Import pygame Import time Import sys CODE = {'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 ':'----.' } ONE_UNIT = 0.5 THREE_UNITS = 3 * ONE_UNIT SEVEN_UNITS = 7 * ONE_UNIT PATH = 'morning _ sound_files /' Def verify (string ): Keys = CODE. keys () For char in string: If char. upper () not in keys and char! = '': Sys. exit ('error the charcter '+ char + 'cannot be translated to Morse Code ') Def main (): Print 'Welcome to Alphabet to Morse Code Translator v.01 \ N' Msg = raw_input ('enter Message :') Verify (msg) Print Pygame. init () For char in msg: If char = '': Print ''' * 7, Time. sleep (SEVEN_UNITS) Else: Print CODE [char. upper ()], Pygame. mixer. music. load (PATH + char. upper () + '_morse_code.ogg ') Pygame. mixer. music. play () Time. sleep (THREE_UNITS) If _ name _ = "_ main __": Main () |