具体要求
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.
Input Specification:
Each input file contains one test case. Each case occupies one line which contains an N (≤10
?100
?? ).
Output Specification:
For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.
Sample Input:
12345
Sample Output:
one five
具体思路
?的,python写这个就是傻瓜思路,不可能不会好吧,初学python,多多指教
具体代码
nm=input("")/*输入个字符串*/
l=len(nm)
su=0
for i in range(l):su=su+int(nm[i])
op=list(str(su))/*数字转化为列表*/
l=len(op)
for i in range(l):if i!=0:print(" ",end="")if op[i]=="1":print("one",end="")elif op[i]=="2":print("two",end="")elif op[i]=="3":print("two",end="")elif op[i]=="4":print("frou",end="")elif op[i]=="5":print("five",end="")elif op[i]=="6":print("six",end="")elif op[i]=="7":print("seven",end="")elif op[i]=="8":print("eight",end="")elif op[i]=="9":print("nine",end="")elif op[i]=="0":print("zero",end="")
就简单,我代码就丑,多多练习进步,代码仅供参考