TVP

# 人民币大写转换中的数据思维

['圆','拾','百','千','万','拾','百','千','亿','拾','百','千','万','拾','百','千','兆']

# -*- coding: utf-8 -*-

def Num2Money(num):

result=''

format_word = ["元","拾","百","千","万","拾","百","千","亿","拾","百","千","万","拾","百","千","兆"]

dic= {"0":"零","1":"壹","2":"贰","3":"叁","4":"肆","5":"伍","6":"陆","7":"柒","8":"捌","9":"玖"}

rNum=reverseNum(num)

for i in range(len(rNum)-1,-1,-1):

seq=rNum[i]

if seq!='0':

result=result+dic[seq]+format_word[i]

else:

if i%4==0:#万、亿等位

result=result+format_word[i]

else:

if result[-1]!='零':

result=result+'零'

if '.' in num:

result=result+dic[num[-2]]+'角'+dic[num[-1]]+'分'

else:

result=result+'整'

result=result.replace('零万','万').replace('亿万','亿零').replace('零零','零').replace('零元','元')

return result

def reverseNum(n):

if '.' in n:

s=n.split('.')[0]

else:

s=n

l = list(s) #模拟全部入栈

result = ""

while len(l)>0:

result += l.pop() #模拟出栈

return result

while 1:

ipt=input('请输入金额：\n')

print(Num2Money(ipt)

getMoney

1、数据结构很重要，决定了能否方便读取、存入、联合。

2、思路不能僵化，不能事前通盘考虑，亦可事后修补。

3、先完成主体功能，再逐步细化，重点在基本算法。

• 发表于:
• 原文链接https://kuaibao.qq.com/s/20180531G0Q2M000?refer=cp_1026
• 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号（企鹅号）传播渠道之一，根据《腾讯内容开放平台服务协议》转载发布内容。
• 如有侵权，请联系 cloudcommunity@tencent.com 删除。

2022-11-30

2018-05-29

2022-11-30

2022-11-30

2022-11-30