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 '-'.
Note: You need to replace both uppercase and lowercase characters. You can ignore replacing all characters that are not letters.
input: python learning
output:16-25-20-8-15-14 12-5-1-18-14-9-14-7
Explanation
For example, if the given 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 the output should be "16-25-20-8-15-14".
letters = 'abcdefghijklmnopqrstuvwxyz'
print(' '.join(['-'.join([str(letters.index(ch) + 1) if ch in letters else ch for ch in word.lower()]) for word in
input().split()]))
Comments
Leave a comment