📅  最后修改于: 2022-03-11 14:57:47.462000             🧑  作者: Mango
def rot(c,n):
""" rotate c forward by n characters,
wrapping as needed; only letters change
"""
if 'a' <= c <= 'z': # lower-case
new_ord = ord(c) + n
if new_ord > ord('z'):
new_ord = new_ord - (2*n)
elif 'A' <= c <= 'Z': # upper-case
new_ord = ord(c) + n
if new_ord > ord('Z'):
new_ord = new_ord - (2*n)
else: # non-alpha
new_ord = ord(c)
return chr(new_ord)