Answer to Question #205035 in Python for p.kusal

Question #205035

Secret Message - 2

Given a string, write a program to print a secret message that replaces characters with numbers 'a' with 1, 'b' with 2, ..., 'z' with 26 where characters are separated by '-'.

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26


Input

Input will be a string in single line containing spaces and letters both uppercase and lowercase.

Output

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

Explanation

For example, if input is "python", "p" should replaced with "16", similarly"y" with "25","t" with "20","h" with "8","o" with "15","n" with "14". So output be "16-25-20-8-15-14".

Sample Input 1

python


Sample Output 1

16-25-20-8-15-14

Sample Input 2

python learning


Sample Output 2

16-25-20-8-15-14 12-5-1-18-14-9-14-7
1
Expert's answer
2021-06-09T08:55:23-0400
cipher = {}
for code, letter in enumerate('abcdefghijklmnopqrstuvwxyz', 1):
    cipher[ord(letter)] = str(code) + '-'
S = input('Input string: ').lower().split()
for word in S:
    print(word.translate(cipher)[:-1], end=' ')

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