Answer to Question #231256 in Python for bhuvana

Question #231256

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


1
Expert's answer
2021-09-01T23:58:51-0400
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))

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