Answer to Question #202188 in Python for Kusal Phanindra

Question #202188

Secret Message - 1

Given a string, write a program to mirror the characters of the string in alphabetical order to create a secret message.


Note: Mirroring the characters in alphabetical order replacing the letters 'a' with 'z', 'b' with 'y', ... , 'z' with 'a'. You need to mirror both uppercase and lowercase characters. You can ignore mirroring for all characters that are not letters.


a b c d e f g h i j k l m n o p q r s t u v w x y z

z y x w v u t s r q p o n m l k j i h g f e d c b a


Explanation

Input

For example, if the given input is "python", "p" should replaced with "k", similarly "y" with "b", "t" with "g", "h" with "s", "o" with "l", "n" with "m". So the output should be "kbgslm".


Sample Input 1

python


Sample Output 1

kbgslm


Sample Input 2

Foundations


Sample Output 2

Ulfmwzgrlmh




1
Expert's answer
2021-06-02T12:14:32-0400
import string
def getSecretCharacter(character):
    characters = string.ascii_lowercase
    mirrorCharacters = characters[::-1]
    for i in range(0,len(characters)):
        if character.islower() and character==characters[i]:
            return mirrorCharacters[i]
        if character.isupper() and character==characters[i].upper():
            return mirrorCharacters[i].upper()
    return None


message = input()
secretMessage=""
for character in message:
    reverseCharacter=getSecretCharacter(character)
    if(reverseCharacter==None):
        secretMessage+=character
    else:
        secretMessage+=str(reverseCharacter)


print(secretMessage)




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