Answers for "rot( c, n)"

0

rot( c, n)

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)
Posted by: Guest on October-13-2021

Browse Popular Code Answers by Language