|

楼主 |
发表于 2024-9-3 16:41:48
|
显示全部楼层
帮我看下下面这套代码:
class ZH_INT:
def __init__(self, num):
self.num = num
def __int__(self):
try:
return int(self.num)
except ValueError:
zh = {'两':2,"零":0, "一":1, "二":2, "三":3, "四":4, "五":5, "六":6, "七":7, "八":8, "九":9,
"壹":1, "贰":2, "叁":3, "肆":4, "伍":5, "陆":6, "柒":7, "捌":8, "玖":9, }
ch = {'十':10,'百':100,'千':1000,'万':1.0e4,'亿':1.0e8}
result = ''
for each in self.num:
if each in zh:
result += str(zh[each])
elif each in ch:
continue
elif each.isdigit():
result += each
if self.num[-1] in ch:
result *= ch[self.num[-1]]
return int(result)
为什么我在相继输入n = ZH_INT("两百五十"),int(n)之后的结果不是250 |
|