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?
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))
Comments
Leave a comment