モールス符号変換

1777 ワード

モルスコード中・と区別することに注意し、
「-」と「-」、「-」.「と」・の相互変換:
pythonコードは次のとおりです.
 # -*- coding:utf-8 -*-

def runnow(ciphertext):
    result=''
    l = list(ciphertext)
    for i in range(0,len(ciphertext)):
       if l[i] == '.':
          l[i] = '·'
       elif l[i] =='-':
           l[i]='—'
       else:
          l[i] = ciphertext[i]

    newS = ''.join(l)
    return newS

ciphertext='-.-. -.-. -.. -.. -.. -.-. -.-. -.. -.-. -.. -..'
print runnow(ciphertext)