大家应该都知道,银行打印账单有时候会跟上人民币的阿拉伯数字以及人民币汉字大写写法,转换的过程中有一定的逻辑难度,较为麻烦,所以笔者心血来潮,花了点时间简单实现了一下这一转换过程,以供初学者参考。

输入样例:

123.22

输出样例:

壹佰贰拾叁圆贰角贰分

参考代码:

#!/usr/bin/env python

# encoding: utf-8

from __future__ import print_function

import sys

import re

import base64

import time

import os

import getpass

reload(sys)

sys.setdefaultencoding("utf-8")

char_arr_01 = [u"零".decode("utf8"), u"壹".decode("utf8"), u"贰".decode("utf8"), u"叁".decode("utf8"), u"肆".decode(

"utf8"), u"伍".decode("utf8"), u"陆".decode("utf8"), u"柒".decode("utf8"), u"捌".decode("utf8"), u"玖".decode("utf8")];

char_arr_02 = [u"圆".decode("utf8"), u"拾".decode("utf8"), u"佰".decode("utf8"), u"仟".decode("utf8"), u"万".decode("utf8"), u"拾".decode("utf8"), u"佰".decode("utf8"), u"仟".decode(

"utf8"), u"亿".decode("utf8"), u"拾".decode("utf8"), u"佰".decode("utf8"), u"仟".decode("utf8"), u"万".decode("utf8"), u"拾".decode("utf8"), u"佰".decode("utf8")]

char_arr_03 = [u"分".decode("utf8"), u"角".decode("utf8")]

def calcRMB():

sum_arr = []

in_str_dot = ""

in_str_Big = ""

flag = 0

dot_count = 0

in_str = raw_input("Please input number : ")

for i in in_str:

if i == '.':

dot_count += 1

elif ord(i) <= ord('z') and ord(i) >= ord('A'):

print("Error")

return

if len(in_str) > 12 or dot_count > 1:

print("Error")

return

in_str = unicode(in_str).decode("utf8")

out_str = ""

if in_str.find('.') != -1:

flag = 1

sum_arr = in_str.split('.')

in_str_Big = sum_arr[0]

if flag==1:

in_str_dot = sum_arr[1]

for i in range(len(in_str_Big)):

if cmp(in_str_Big[i],'0') == 0 and (len(in_str_Big)-1-i)%4 != 0:

out_str = out_str + char_arr_01[ord(in_str_Big[i])-ord('0')]

else:

out_str = out_str + char_arr_01[ord(in_str_Big[i])-ord('0')]

out_str = out_str + char_arr_02[len(in_str_Big)-1-i]

while out_str.find(u"零零".decode("utf8")) != -1:

out_str = out_str.replace(u"零零".decode("utf8"), u"零".decode("utf8"))

out_str = out_str.replace(u"零亿".decode("utf8"),u"亿".decode("utf8"))

out_str = out_str.replace(u"零万".decode("utf8"),u"万".decode("utf8"))

if out_str != u"零元".decode("utf8"):

out_str = out_str.replace(u"零圆".decode("utf8"),u"圆".decode("utf8"))

if len(in_str_dot) > 2 and flag == 1:

print("False !!")

return

if flag == 1:

for i in range(len(in_str_dot)):

out_str = out_str + char_arr_01[ord(in_str_dot[i])-ord('0')]

out_str = out_str + char_arr_03[len(in_str_dot)-1-i]

print(out_str)

def main():

while 1:

os.system("cls")

calcRMB()

print()

end_flag = raw_input("Try Again ? (y/n)")

if end_flag == 'y' or end_flag == 'Y':

continue

elif end_flag == 'n' or end_flag == 'N':

break

else:

print("\nError!!")

break

if __name__ == '__main__':

main()

python人民币小写转大写_Python小程序 -- 人民币小写转大写辅助工具相关推荐

  1. python人民币小写转大写_Python小程序人民币小写转大写辅助工具

    大家应该都知道,银行打印账单有时候会跟上人民币的阿拉伯数字以及人民币汉字大写写法,转换的过程中有一定的逻辑难度,较为麻烦,所以笔者心血来潮,花了点时间简单实现了一下这一转换过程,以供初学者参考. 输入 ...

  2. python给四个人发牌_python小程序之4名牌手洗牌发牌问题解析

    本文为大家解析了python实现4名牌手洗牌发牌的问题,供大家参考,具体内容如下 编写程序, 4名牌手打牌,计算机随机将52张牌(不含大小鬼)发给4名牌手,在屏幕上显示每位牌手的牌.创建函数gen_p ...

  3. python计算一元二次_Python小程序-写一个计算一元二次方程的程序函数

    题目要求: 请定义一个函数quadratic(a, b, c),接收3个参数,返回一元二次方程:ax^2 + bx + c = 0的两个解. 程序代码: 这只是一个函数,如果你不调用它的话,是不会产生 ...

  4. 数字用计算机写大写,微信小程序学习用:大写计算器;数字转换为大写

    [AppleScript] function digitUppercase(n) { var fraction = ['角', '分']; var digit = [ '零', '壹', '贰', ' ...

  5. python软件代码示例-用Python写一个模拟qq聊天小程序的代码实例

    Python 超简单的聊天程序 客户端: import socket, sys host = '10.248.27.23' # host = raw_input("Plz imput des ...

  6. Python 练习册,每天一个小程序

    Python 练习册,每天一个小程序 说明: Python 练习册,每天一个小程序.注:将 Python 换成其他语言,大多数题目也适用 不会出现诸如「打印九九乘法表」.「打印水仙花」之类的题目 点此 ...

  7. 能不能用python开发qq_用Python写一个模拟qq聊天小程序的代码实例

    用Python写一个模拟qq聊天小程序的代码实例 发布时间:2020-09-09 07:49:29

  8. python+requests对app和微信小程序进行接口测试

    对于web端和app端的接口测试来说,他们都是通过请求方法,url和传递的body参数进行接口请求,区别web和app的区别就是header请求的不同.不同的地方在于header中的User-Agen ...

  9. python扫描app接口_[分享】python+requests对app和微信小程序进行接口测试

    对于web端和app端的接口测试来说,他们都是通过请求方法,url和传递的body参数进行接口请求,区别web和app的区别就是header请求的不同.不同的地方在于header中的User-Agen ...

最新文章

  1. 完整代码+实操!手把手教你操作Faster R-CNN和Mask R-CNN
  2. 自学使用sort他命令使用
  3. python调用bat有时可以、有时不行_python编程实现对远程执行bat文件时遇到的错误...
  4. 二叉树 —— 创建二叉树 先序遍历 、中序遍历、后序遍历(递归方式、非递归方式)
  5. 022_配置configuration
  6. C#中WinForm程序退出方法
  7. golang的GUI库,使用go-fyne设计一个代办事项APP
  8. apache apollo_Apache Apollo REST API
  9. clickhouse入门与安装
  10. PHP问题 —— failed to open stream: HTTP request faile
  11. linux 离线迅雷下载软件,Linux 迅雷离线客户端!!!!!!!!!!!!
  12. mpaaS的kylin框架-项目结构(脚手架)
  13. FaceBook爬取库:facebook-scraper
  14. 你不逼自己一把 你怎么知道自己有多优秀
  15. php空间开启伪静态,php虚拟主机开启伪静态(虚拟主机伪静态规则配置)
  16. Java反射的基本理解
  17. 【机器学习】贝叶斯分类三大实战项目:高斯模型进行疾病诊断、多项式模型进行文本分类、伯努利模型进行好/差评判别
  18. 《基础微积分教材中译版》上线计划预告
  19. 人工智能是不是对人体油画有什么误会?
  20. 【Python·OpenCV】如何实现 HSV 与灰度图的相互转换?

热门文章

  1. 【PHP】PHP MySQL问题 phpinfo() 没有显示MySQL模块
  2. Inwook,Kong
  3. WebService(腾讯QQ在线状态 WEB 服务)
  4. 机器学习3决策树算法模型
  5. java构建器出错nullpoint_空指针错误 java.lang.NullPointerException 浅谈
  6. html2canvas解决图片空白,网络图片跨域
  7. [原创] Photoshopt午简单的调出暗青色效果
  8. 安规之电气间距和爬电距离
  9. jsliang 求职系列 - 40 - CSS 移动端
  10. 利用Python暴力破解邻居家WiFi密码