We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importmathimportosimportrandomimportreimportsys## Complete the 'caesarCipher' function below.## The function is expected to return a STRING.# The function accepts following parameters:# 1. STRING s# 2. INTEGER k#defcaesarCipher(s,k):# Write your code heretmp_list=list('abcdefghijklmnopqrstuvwxyz')tmp_list1=list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')s=list(s)foriinrange(len(s)):ifs[i]intmp_list:s[i]=tmp_list[(tmp_list.index(s[i])+k)%26]elifs[i]intmp_list1:s[i]=tmp_list1[(tmp_list1.index(s[i])+k)%26]return''.join(s)if__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')n=int(input().strip())s=input()k=int(input().strip())result=caesarCipher(s,k)fptr.write(result+'\n')fptr.close()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Caesar Cipher
You are viewing a single comment's thread. Return to all comments →