Advertisement
JachyHm

Morses code translator

Jan 26th, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. zdroj = open('preloz.mors','r')
  2. cil = open('prelozene.txt','w')
  3. x = ' '
  4. text=''
  5. pismenko=''
  6. pismenkoM=''
  7. prevX = ''
  8. mezera = ''
  9. dict = {"•-":'a',".-":'a',"-•••":'b',"-...":'b',"-•-•":'c',"-.-.":"c","-••":'d',"-..":"d","•":'e',".":"e","••-•":'f',"..-.":"f","--•":'g',"--.":"g","••••":'h',"....":"h","••":'i',"..":"i","•---":'j',".---":"j","-•-":'k',"-.-":"k","•-••":'l',".-..":"l","--":'m',"-•":'n',"-.":"n","---":'o',"•--•":'p',".--.":"p","--•-":'q',"--.-":"q","•-•":'r',".-.":"r","•••":'s',"...":"s","-":'t',"••-":'u',"..-":"u","•••-":'v',"...-":"v","•--":'w',".--":"w","-••-":'x',"-..-":"x","-•--":'y',"-.--":"y","--••":'z',"--..":"z","/":' ',"••--••":'?',"..--..":"?","--..--":",","--••--":",","---••":"8","••---":"2","-•-•-•":";","-----":"0","•----":"1","-•--•-":"(","--•••":"7","---•••":":","•••••":"5","-••••-":"-","--•••-":"!","----•":"9","•••--":"3","-••-•":"/","-••••":"6","••••-":"4","-•••-":"=","•--•-•":"@"};
  10. while(x!=''):
  11.     x = zdroj.read(1)
  12.     pismenko=''
  13.     if (x=='/'):
  14.         if (pismenkoM!=''):
  15.             pismenko = dict[pismenkoM]
  16.             pismenkoM=''
  17.             text = text + pismenko
  18.         mezera=mezera+'/'
  19.     elif (x!=' '):
  20.         pismenkoM = pismenkoM + x
  21.         prevX = x
  22.     if (x!='/' and x!=' '):
  23.         mezera=''
  24.     if (mezera == '//'):
  25.         text = text + ' '
  26.         mezera=''
  27. cil.write(str(text))
  28. cil.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement