Answer to Question #198373 in Python for meghana

Question #198373

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

stuvwxyz1920212223242526



1
Expert's answer
2021-05-25T05:21:53-0400
key = 'abcdefghijklmnopqrstuvwxyz'


def shifr(sen:str, key:str):


	res = ''
	for ch in sen:
		if ch == ' ':
			res = res[:-1] + ch 
			continue
		if ch.lower() in key:
			res += str(key.index(ch.lower()) + 1)
		else:
			res += ch
		res += '-'
	return res[:-1]




while True:
	print(shifr(input(), key))




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