Python Morse

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/BLueberry_Pie/article/details/84656995

Morse.py

# -*- coding:utf-8 -*-
def Morse():
    try:
        s = input()
        codebook = {
            'A':".-",
            'B':"-...",
            'C':"-.-.",
            'D':"-..",
            'E':".",
            'F':"..-.",
            'G':"--.",
            'H':"....",
            'I':"..",
            'J':".---",
            'K':"-.-",
            'L':".-..",
            'M':"--",
            'N':"-.",
            'O':"---",
            'P':".--.",
            'Q':"--.-",
            'R':".-.",
            'S':"...",
            'T':"-",
            'U':"..-",
            'V':".--",
            'W':".--",
            'X':"-..-",
            'Y':"-.--",
            'Z':"--..",
            '1':".----",
            '2':"..---",
            '3':"...---",
            '4':"....-",
            '5':".....",
            '6':"-....",
            '7':"--...",
            '8':"---..",
            '9':"----.",
            '0':"-----",
            '.':".━.━.━",
            '?':"..--..",
            '!':"-.-.--",
            '(':"-.--.",
            '@':".--.-.",
            ':':"---...",
            '=':"-...-",
            '-':"-....-",
            ')':"-.--.-",
            '+':".-.-.",
            ',':"--..--",
            '\'':".----.",
            '_':"..--.-",
            '$':"...-..-",
            ';':"-.-.-.",
            '/':"-..-.",
            '\"':".-..-.",
        }
        clear = ""
        cipher = ""

        while 1:
            ss = s.split(" ");
            for c in ss:
                for k in codebook.keys():
                    if codebook[k] == c:
                        cipher+=k
            print(cipher)
            break;

    except Exception as e:
        print("",end="")




if __name__ == '__main__':

    try:
        while True:
            Morse()
    except EOFError:
        exit()


猜你喜欢

转载自blog.csdn.net/BLueberry_Pie/article/details/84656995
今日推荐