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)
评论列表
文章目录