python人民币小写转大写_python人民币小写转大写辅助工具
本文实例为大家分享了python人民币大小写转换的具体代码,供大家参考,具体内容如下
大家应该都知道,银行打印账单有时候会跟上人民币的阿拉伯数字以及人民币汉字大写写法,转换的过程中有一定的逻辑难度,较为麻烦,所以笔者心血来潮,花了点时间简单实现了一下这一转换过程,以供初学者参考。
输入样例:
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()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
时间: 2018-06-19
python人民币小写转大写_python人民币小写转大写辅助工具相关推荐
- python跳一跳编程构造_python实现微信跳一跳辅助工具步骤详解
说明 1.windows上安装安卓模拟器,安卓版本5.1以上 2.模拟器里下载安装最新的微信6.6.1 3.最好使用python2.7,python3的pyhook包有bug,解决比较麻烦 步骤 1. ...
- python hook pc微信_python实现微信跳一跳辅助工具步骤详解
说明 1.windows上安装安卓模拟器,安卓版本5.1以上 2.模拟器里下载安装最新的微信6.6.1 3.最好使用python2.7,python3的pyhook包有bug,解决比较麻烦 步骤 1. ...
- python hook 微信_python实现微信跳一跳辅助工具步骤详解
说明 1.windows上安装安卓模拟器,安卓版本5.1以上 2.模拟器里下载安装最新的微信6.6.1 3.最好使用python2.7,python3的pyhook包有bug,解决比较麻烦 步骤 1. ...
- python数字转中文大写_Python 人民币数字转汉字表示 —— 大写金额
# coding: utf-8 import warnings from decimal import Decimal def cncurrency(value, capital=True, pref ...
- python人民币转大写_python 人民币数字转大写中文
def digital_to_chinese(digital): str_digital = str(digital) chinese = {'1': '壹', '2': '贰', '3': '叁', ...
- python数字转换成中文大写_python 人民币数字转大写中文
def digital_to_chinese(digital): str_digital = str(digital) chinese = {'1': '壹', '2': '贰', '3': '叁', ...
- python table数据抓取_Python爬虫:数据抓取工具及类库详解
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: ncepu_Chen PS:如有需要Python学习资料的小伙伴可以 ...
- python跳一跳编程构造_Python + 新手 制作“跳一跳”辅助程序
刚开始学习Python,萌新总有一颗渴望做实践享受成就感的心,最近"跳一跳"比较火,在看了一些前辈的辅助程序教程后,我就也想写一个自己版本的辅助(for Android). 写辅助 ...
- python爬取ppt代码_Python爬取PPT模板小工具
由于很多PPT抓取工具都会因为版本问题无法使用,所以论坛大神就自己写了这款Python爬取PPT模板小工具,可以帮助用户轻松获取各种PPT模板,使用的时候注意一次只能下载一种类型.软件仅供交流学习,下 ...
- python最简单的语言_Python语言的简单实用小工具
本文主要向大家介绍了Python语言的简单实用小工具,通过具体的内容向大家展示,希望对大家学习Python语言有所帮助. 在python进行自动化编写的过程中,常常需要造一些数据,比如,获取随机的合法 ...
最新文章
- vc++给控件添加消息和函数
- mysql 存储过程基础_MySQL基础-存储过程
- 人工智能时代,怎样高效学习AI技术、聚焦AI行业趋势?
- element upload预览_vue+element上传图片并显示预览图
- linux find命令详解--转
- Angular self study 5 - remove ng-app
- qt与JAVA服务器通信_Qt实现的SSL通信客户端和服务器
- iPhone 12包装盒设计曝光,没充电器没耳机实锤?
- 32 位的有符号整数_「js基础」JavaScript逻辑和位运算符归纳
- 使用vue-qriously插件,在vue项目中生成二维码
- 现代操作系统 第十章 UNIX、Linux 和 Android 下
- SLAM | 视觉SLAM中特征点法开源算法:PTAM、ORB-SLAM
- 超级简单得App自动化demo,有手就会,Weditor + uiautomator2 实现app自动化
- 如何用手机快捷设计品牌宣传的海报图片和视频
- 河南农信社数字化转型实践方案
- 免费下载国际学术论文SCI期刊文献软件,SCI-HUB EVA
- 朋友入职中软一个月(外包华为)就离职了
- USACO4.1 篱笆回路Fence Loops
- 网络编程使用标准I/O的危险以及正确使用RIO包
- 公共场所常用英语标识
热门文章
- Flutter 2.10 正式发布,包含 Windows 平台正式版,快来看看有什么新内容
- perl 模块下载安装
- mysql 关闭远程_禁止MySQL root远程访问
- linux安装硬盘超过2t,linux 硬盘超过2T问题
- 【教程】安装torch_sparse、torch_cluster、torch_scatter、torch_spline
- 数字系统设计, 8个经典计数器电路方案合辑
- 学习W5500的OTA平台的SDK
- 7-1 电话聊天狂人
- trivial/nontrival函数
- 关于JAVA开发小游戏如何做读档和存档功能的这件事