初学Python:银行金额数字转大写汉字

初学Python:银行金额数字转大写汉字


在这里插入图片描述

list_chinese = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖', '拾']
list_unit = ['圆', '拾', '佰', '仟', '萬']

price = input('input 金额 五位以下: ')
price = int(price[:5])  # 去首0
list_price = list(str(price))

end_zero = 1  # 末尾是否为0
flag = 1  # 当前是否为0
len_price = len(list_price)

for i in range(len_price):
    list_price[i] = list_chinese[int(list_price[i])]  # 转大写

zero = list_chinese[0]  # 零

if list_price[-1] == zero:
    end_zero = 0

for i in range(len_price):
    if i == len_price - 1 and end_zero == 0:
        print(list_unit[0], end='')
        break
    elif i == len_price - 1 and end_zero == 1:
        print(list_price[i], end='')
        print(list_unit[len_price - i - 1], end='')
    else:
        if list_price[i] == zero:
            flag = 0  # 当前为0
        else:
            flag = 1
        if flag == 1 or (flag == 0 and list_price[i - 1] != zero and end_zero == 1):
            print(list_price[i], end='')
        if flag == 1 and i != len_price - 1:  # 若当前不为0
            print(list_unit[len_price - i - 1], end='')

print('整')

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述


End.

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值