Python摩斯密码加密程序
def morse_code_encryption(text): '接收明文字符串为参数,返回用摩斯密码加密后的字符串。'
ls = ('.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', '..', '.---', '-.-', '.-..', '--', '-.', '---',
'.--.', '--.-', '.-.', '...', '-', '..-', '...-', '.--', '-..-', '-.--', '--..')
message = ''
for char in text.lower():
if char == ' ':
message += ' '
elif char.isalpha():
index = ord(char) - ord('a')
message += ls[index] + ' '
else:
message += char
return message
text = input() print(morse_code_encryption(text))
原文地址: https://www.cveoy.top/t/topic/oLVX 著作权归作者所有。请勿转载和采集!