Hide String
Anit is given a sentence S.He wants to create an encoding of the sentence. The encoding works by replacing each letter with its previous letter as shown in the below table. Help Anil encode the
sentence.
Letter
Previous Letter
A
B
A
Note: Consider upper and lower case letters as different.
Input
The first line of input is a string S
def previous(letter):
if letter == 'a':
return 'z'
if letter == 'A':
return 'Z'
if not letter.isalpha(): #checking is symbol a letter
return letter
return chr(ord(letter) - 1) #getting previus symbol by Unicode number
s = input()
encoded_s = ''
for letter in s:
encoded_s += previous(letter)
print(encoded_s)
Simple input: aA Bc: zX7!
Simple output: zZ Ab: yW7!
Comments
Leave a comment