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)}')
全部评论
(0) 回帖