rot13.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:IntroPython2016 作者: UWPCE-PythonCert 项目源码 文件源码
def rot13b(text):
    """
    A little smarter to use % to take care of the wrap-around

    And do a check on the ord value, rather than looking in
    string.ascii_lowercase
    """
    # loop through the letters in teh input string
    new_text = []
    for c in text:
        o = ord(c)
        # do upper and lower case separately
        if a <= o <= z:
            o = a + ((o - a + 13) % 26)
        elif A <= o <= Z:
            o = A + ((o - A + 13) % 26)
        new_text.append(chr(o))
    return "".join(new_text)

# Translation table for 1 byte string objects:
# Faster if you build a translation table and use that


# build a translation table:
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号