Answer to Question #280454 in Python for adhichinna

Question #280454

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


1
Expert's answer
2021-12-17T06:57:07-0500
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!


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS