I was doing some competitive programming and stumbled upon a ROT13 question that required me to increment each alphabet by 13.
This was my attempt
def rot13(message):
l2 = []
l1 = list(message)
for i in l1:
i = str(i)
for i in l1:
if ord('a') <= ord(i) <= ord('z'):
i = chr((ord(i) + 13) % 26 + ord('a'))
l2.append(i)
elif ord('A') <= ord(i) <= ord('Z'):
i = chr((ord(i) + 13) % 26 + ord('A'))
l2.append(i)
return l2
It was returning wrong outputs such as
For input - test , it gave output - zkyz while correct is "grfg"
For input - Test , output was Tkyz while it should be Grfg
I haven't joined the list yet as I was first trying to get the right answer.
'A'starts out as 65, not 0.