Answer to Question #222658 in Python for krish

Question #222658

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


Note: You need to replace both uppercase and lowercase characters. You can ignore replacing all characters that are not letters.


abcdefghij12345678910

klmnopqr1112131415161718

stuvwxyz1920212223242526Input


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



Input 1

python

Output 1

16-25-20-8-15-14


Input2

python learning

Output 2

16-25-20-8-15-14 12-5-1-18-14-9-14-7





1
Expert's answer
2021-08-02T15:55:27-0400
keys = 'abcdefghijklmnopqrstuvwxyz'
s = input()
res = ''
for i in range(len(s)):
	if s[i] in keys:
		res += str(keys.index(s[i]) +1)
	else:
		res += s[i]
	if s[i] == ' ' :
		continue
	if i < (len(s) - 1):
		if s[i+1] == ' ':
			continue
		res += '-'
print(res)

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