rot13.py 文件源码

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

项目:IntroPython2016 作者: UWPCE-PythonCert 项目源码 文件源码
def rot13a(text):
    """
    My first solution: brute force
    """
    # loop through the letters in the input string
    new_text = []
    for c in text:
        # do upper and lower case separately
        if c in string.ascii_lowercase:
            o = ord(c) + 13
            if o > z:
                o = a-1 + o-z
        elif c in string.ascii_uppercase:
            o = ord(c) + 13
            if o > Z:
                o = A-1 + o-Z
        else:
            o = ord(c)
        new_text.append(chr(o))
    return "".join(new_text)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号