Answer to Question #214050 in Python for sree

Question #214050

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?


1
Expert's answer
2021-07-06T00:32:37-0400
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))

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