请把以下内容编写成Python一个程序2 集合与字典摩斯密码又译为摩尔斯电码Morse code是一种时通时断的信号代码通过不同的排列顺序来表达不同的英文字母、数字和标点符号。
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/hi9M 著作权归作者所有。请勿转载和采集!