- 论坛徽章:
- 0
|
回复 #23 作业没做完 的帖子
metres = float(raw_input("Enter the height (in metres): "))
a = {1:'one',2:'two',3:'three',4:'four',5:'five',6:'six',\
7:'seven',8:'eight',9:'nine',10:'ten',20:'twenty',\
30:'thirty',40:'forty',50:'fifty',60:'sixty',70:'seventy',\
80:'eighty',90:'ninety',100:'hundred',\
1000:'thousand '}
T=total_inches = 39.37 * metres
F=feet = (int(T//12))
SF=str(F)
I=round(float(T/12)-F,1)
II=int(I*10)
if len(SF)==1:
print "It is " + str(a[F])+" feet, " + str(a[II]) + ' inches high.'
if len(SF)==2:
L=F-F//10*10
print "It is " + str(a[F//10*10])+str(a[L]) + " feet,"+\
str(a[II]) + ' inches high.'
if len(SF)==3:
H=F//100
TEN=(F-F//100*100)//10*10
OO=(F-F//100*100)-TEN
print "It is " + str(a[H])+' hundred'+" "+str(a[TEN])+" "+a[OO]+\
" feet,"+ str(a[II]) + ' inches high.'
我刚学没多久 我这个是比较笨的,我所学的知识中我只知道这样子是可以实现你那个功能的,这仅仅是一种思路。注意11~19我忘记添加了疏忽了。所以遇到11的时候可能会打出tenone你自己改下就可以了,但理论上你可以用他稍微修改可以做出无限的数字,当然计算机的处理能力是有限的实际中你也用不大那么大的数字,
其中 我的思路就是用len() 函数来判断 这个数字是个几位数?
如果你有兴趣不怕烦 你可以自己跟着这个思路做到 千万位,亿万位,当然词典要记得添加一下关键字,重复性的用公式把他分化掉
我的思路就是比如说 11111就= 1万+1千+1百+十一,这个至少比 你在词典从1~11111要轻松不是么?
希望能帮助到你,共同进步吧
PS写这个东东花了我2个多小时 另我英语基础很差 我不知道老外表达 数字时 是不是这样表达的! |
|