Python版,里面还有些不完善的点,欢迎指正

#!/usr/bin/env python """ transform word to number like mobile phone """ version=0.2 author='liwei.an' mod="abcdefghijklmnopqrstuvwxyz" mod=mod+mod.upper() def check_word(word): for i in range(2):  for j in word:  if j not in mod:
                print("number in the 'word',please input again!")
                word=raw_input("input a word: ")  else: break else: break map={'x0':'','x1':'','x2':"abc",'x3':'def','x4':'ghi','x5':'jkl','x6':'mno','x7':'pqrs','x8':'tuv','x9':'wxyz'} def word_to_number(word):
    number="" for i in word.lower():  for j in map.keys(): if i in map[j]:
            number +=j
    number=number.replace("x","")  return number if __name__ == '__main__':
    word=raw_input('input a word: ')
    check_word(word)
    number = word_to_number(word)
    print("{0} => {1}".format(word,number))

#Python##学习路径#
全部评论
很奇怪,格式乱了
点赞
送花
回复
分享
发布于 2020-05-24 22:05

相关推荐

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