Essentially, the alphabets in the input string are cyclically rotated by k and the rest of the characters retains their form. I'm puzzled by a mismatch. For my code:
import math
import os
import random
import re
import sys
# Complete the caesarCipher function below.
def caesarCipher(s, k):
st = []
for i in range(0,len(s)):
if 65<=ord(s[i])<=90:
temp = ord(s[i])+k
if (temp>90):
temp-=26
st.append(chr(temp))
elif 97<=ord(s[i])<=122:
temp = ord(s[i])+k
if (temp>122):
temp-=26
st.append(chr(temp))
else: st.append(s[i])
return ''.join(st)
if __name__ == '__main__':
s = input()
k = int(input())
result = caesarCipher(s, k)
The output always fails by one, like My: okffng-Qwvc Expected: okffng-Qwvb
My:Fqcfex-Qttp-ts-ymj-Gwnlmy-Xnij-tk-Qnkj Expected: Fqbfdx-Qttp-ts-ymj-Gwnlmy-Xnij-tk-Qnkj
I can't seem to detect the bug.