2019-06-19:一个字符串I am a boy,请依照如下规则转换为数字。 abc–2, def–3, ghi–4, jkl–5, mno–6, pqrs–7, tuv–8 wxyz–9

def lettersChangeDatas(new_s):
    s_list=new_s.split()
    print(s_list)
    new_s=''
    for words in s_list:
        for letter in words:
            if letter.lower() in "abc":
                new_s+=str(2)
            elif letter.lower() in "def":
                new_s+=str(3)
            elif letter.lower() in "ghi":
                new_s+=str(4)
            elif letter.lower() in "jkl":
                new_s+=str(5)
            elif letter.lower() in "mno":
                new_s+=str(6)
            elif letter.lower() in "pqrs":
                new_s += str(7)
            elif letter.lower() in "tuv":
                new_s += str(8)
            elif letter.lower() in "wxyz":
                new_s += str(9)
    return new_s
print(lettersChangeDatas("I am a boy"))

 

你可能感兴趣的:(Python)