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 '-'.
letters = 'abcdefghijklmnopqrstuvwxyz'
table = {}
for num, i in enumerate(letters, 1):
table[ord(i)] = str(num) + '-'
s = input('Input string: ').lower()
s = s.translate(table).split()
for index in range(len(s)):
s[index] = s[index][:-1]
print(' '.join(s))
Comments
Leave a comment