Answer to Question #205324 in Python for ayushi

Question #205324

When input is "python learning" output displayed is 16-25-20-8-15-14- 12-5-1-18-14-9-14-7 there is additional - after 14 digit. how to rectify this ,kindly guide me?


1
Expert's answer
2021-06-10T10:26:56-0400
key = 'abcdefghijklmnopqrstuvwxyz'


def sec_msg(msg, key):
	res = ''
	for i in range(len(msg)):
		char = msg[i]
		if char.lower() in key:
			res += str(key.index(char)+1)
		else:
			res += char
		if (i+1) < len(msg) and msg[i+1] != ' ' and char != ' ':
			res += '-'
	return res


while True:
	print(sec_msg(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
APPROVED BY CLIENTS