Advertisement
Guest User

morsecode

a guest
Sep 8th, 2012
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. f=open("sequence.txt")#sequence.txt contains all the alphabets and characters which should be converted to morse in the same order as the pdf in the OP
  2. normalCharacters=[]
  3. for i in range(1,43):
  4.     normalCharacters.append(str(f.readline().replace('\n','')))
  5. f.close()
  6. f=open("morse.txt")# morse.txt contains each character converted to morse copied from the pdf
  7. characterInMorse=[]
  8. for i in range(1,43):
  9.     s=str(f.readline())
  10.     s=s.replace('\n','')
  11.     characterInMorse.append(s)
  12. print "Please enter the string to be converted into morse."
  13. userInput= str(raw_input()).upper()#inputting from the user
  14. morsecode=""# will be used to store string in morse
  15. for ch in userInput:
  16.     if ch==' ':
  17.         morsecode=morsecode+"  "#if a word ends two spaces are added
  18.     else:
  19.         if ch=='(':
  20.             morsecode=morsecode+characterInMorse[41]
  21.             continue
  22.         if ch==')':continue            
  23.         index=normalCharacters.index(ch)
  24.         morsecode=morsecode+characterInMorse[index]
  25.         morsecode=morsecode+" "
  26. print "In Morsecode:"
  27. print morsecode          
  28. #contents of sequence.txt http://pastebin.com/ttXGLTn0
  29. #contents of morse.txt http://pastebin.com/TUdmSKPt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement