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))

Python摩斯密码加密程序

原文地址: https://www.cveoy.top/t/topic/oLVX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录