web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

Python语言如何实现大写汉字和数字的转换

394 ℃
     
def chineseNumber2Int(strNum: str):
  result = 0
  temp = 1  # 存放一个单位的数字如:十万
  count = 0  # 判断是否有chArr
  cnArr = ['壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
  chArr = ['拾', '佰', '仟', '万', '亿']
  for i in range(len(strNum)):
    b = True
    c = strNum[i]
    for j in range(len(cnArr)):
      if c == cnArr[j]:
        if count != 0:
          result += temp
          count = 0
        temp = j + 1
        b = False
        break
    if b:
      for j in range(len(chArr)):
        if c == chArr[j]:
          if j == 0:
            temp *= 10
          elif j == 1:
            temp *= 100
          elif j == 2:
            temp *= 1000
          elif j == 3:
            temp *= 10000
          elif j == 4:
            temp *= 100000000
        count += 1
    if i == len(strNum) - 1:
      result += temp
  return result

Mac电脑安装Python软件后怎么查看版本号(附下载地址)

Python语法PDF转Word只需要4行代码

Python语法出现keyerror错误解决方法

python语法中的import语句的正确用法

如何利用Python中生成合成数据的三个库

标签: python语法, Python语言

上面是“Python语言如何实现大写汉字和数字的转换”的全面内容,想了解更多关于 后端开发 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_4292.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > 后端开发
本文共计468个字,预计阅读时长4分钟
生活小工具,收录了80多款小工具
上一篇: 推荐一款免费可商用英文字体——Atkinson Hyperlegible
下一篇: 推荐一款免费好看的中文设计字体——字体传奇特战体
x 打工人ai神器