Simple implemented by python

number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
Alphabet = [' ', ' ', 'abc', 'def', 'ghi', 'jkl', 'mno', 'pqrs', 'tuv', 'wxyz']


def alphabet_to_digital(inputstr):
    result = []
    for i in range(len(inputstr)):
        for j in range(len(Alphabet)):
            if inputstr[i] in Alphabet[j]:
                result.append(number[j])
                break
    result_number = ''.join(result)
    return result_number


def process_input(inputstr):
    inputstr = inputstr.lower()
    return inputstr


if __name__ == '__main__':
    inputstr = process_input(input('please input the string:\n'))
    print(f'the corresponding number is\n{alphabet_to_digital(inputstr)}')

#Python##学习路径#
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务