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

520 ℃
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://m.ipkd.cn/webs_4292.html

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

vuejs利用正则判断只允许输入数字
layui表单如何实现单行和多行(自动换行)
typecho如何替换文章内容的友链
不同种类的app运用不同ajax技术?
php如何读取json文件里面的内容并转为数组