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 issue?
key = 'abcdefghijklmnopqrstuvwxyz'
def sec_msg(msg, key):
res = ''
for i in range(len(msg)):
letter = msg[i]
if letter in key:
res += str(key.index(letter)+1)
else:
res += letter
if (i+1) < len(msg) and msg[i+1] != ' ' and letter != ' ':
res += '-'
return res
inputString = input()
String = inputString.lower()
print(sec_msg(String, key))
Comments
Leave a comment