In [ ]:
ord('a')
Out[ ]:
97
In [ ]:
ord('b')
Out[ ]:
98
In [ ]:
ord('A')
Out[ ]:
65
In [ ]:
chr(97)
Out[ ]:
'a'
In [ ]:
def encode(n,s):
    result = ""
    for c in s:
        if c >= 'a' and c <= 'z':
            result = result + chr(((ord(c) - ord('a')) + n)%26 + ord('a'))
        else:
            result = result + c
    return result
In [ ]:
encode(13,'my name is Raj')
Out[ ]:
'zl anzr vf Rnw'
In [ ]:
chr((ord('a')-ord('a')+13)%26 + ord('a'))
Out[ ]:
'n'
In [ ]:
def encode(n,s):
    result = ""
    for c in s:
        if c >= 'a' and c <= 'z':
            result = result + chr(((ord(c) - ord('a')) + n)%26 + ord('a'))
        else:
            result = result + c
    return result