您的位置:首页 > 编程语言 > Python开发

Python HAIL CAESAR (凯撒密码) 2

2015-06-15 22:14 656 查看
def applyCoder(text, coder):

    """

    Applies the coder to the text. Returns the encoded text.

    text: string

    coder: dict with mappings of characters to shifted characters

    returns: text after mapping coder chars to original text

    """

    ### TODO.

    new = ""

    for word in text:

        if word in string.ascii_lowercase or word in string.ascii_uppercase:

            new = new + coder[word]

        else:

            new = new + word

    return new

少了红色部分一直返回 keyerror /(ㄒoㄒ)/~~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: