Answer to Question #199846 in Python for meghana

Question #199846

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.


abcdefghijklmzyxwvutsrqpon nopqrstuvwxyzmlkjihgfedcbaInput


The input will be a string in the single line containing spaces and letters (both uppercase and lowercase).Output


The output should be a single line containing the secret message. All characters in the output should be in lower case.

Explanation


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".




1
Expert's answer
2021-05-28T00:21:55-0400
alphabet = 'abcdefghijklmnopqrstuvwxyz'
table = dict()
for letter, new_letter in zip(alphabet, alphabet[::-1]):
    table[ord(letter)] = new_letter
s = input('Input string: ')
print(s.translate(table))

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