编程语言
首页 > 编程语言> > python 蓝桥杯--数的读法

python 蓝桥杯--数的读法

作者:互联网

Tom教授正在给研究生讲授一门关于基因的课程,有一件事情让他颇为头疼:一条染色体上有成千上万个碱基对,它们从0开始编号,到几百万,几千万,甚至上亿。
  比如说,在对学生讲解第1234567009号位置上的碱基时,光看着数字是很难准确的念出来的。
  所以,他迫切地需要一个系统,然后当他输入12 3456 7009时,会给出相应的念法:
  十二亿三千四百五十六万七千零九
  用汉语拼音表示为
  shi er yi san qian si bai wu shi liu wan qi qian ling jiu
  这样他只需要照着念就可以了。
  你的任务是帮他设计这样一个系统:给定一个阿拉伯数字串,你帮他按照中文读写的规范转为汉语拼音字串,相邻的两个音节用一个空格符格开。
  注意必须严格按照规范,比如说“10010”读作“yi wan ling yi shi”而不是“yi wan ling shi”,“100000”读作“shi wan”而不是“yi shi wan”,“2000”读作“er qian”而不是“liang qian”。

输入格式

  有一个数字串,数值大小不超过2,000,000,000。

输出格式

  是一个由小写英文字母,逗号和空格组成的字符串,表示该数的英文读法。

样例输入

1234567009

样例输出

shi er yi san qian si bai wu shi liu wan qi qian ling jiu

说明:此方法为笨办法,虽然全部通过了,但是这在考试中绝对是不可取发,我目前水平只能这样做出了,希望以后可以、改进,也希望大家指点我。

n=int(input())
def yw(n):
    if 9>=n>=0:
        if n == 0:
            return "ling"
        if n == 1:
            return "yi"
        elif n == 2:
            return "er"
        elif n == 3:
            return "san"
        elif n == 4:
            return "si"
        elif n == 5:
            return "wu"
        elif  n == 6:
            return "liu"
        elif  n == 7:
            return "qi"
        elif  n == 8:
            return "ba"
        elif  n == 9:
            return "jiu"
def lw(n):
    if 99>=n>=10:
        i = n// 10
        j = n % 10
        if i==1 and j==0:
            return "shi"
        elif i==1 and j!=0:
            q="shi"+" "+yw(j)
            return q
        elif i == 2 and j == 0:
            return "er shi"
        elif i==2 and j!=0:
            q="er shi"+" "+yw(j)
            return q
        elif i == 3 and j == 0:
            return "san shi"
        elif i==3 and j!=0:
            q="san shi"+" "+yw(j)
            return q
        elif i == 4 and j == 0:
            return "si shi"
        elif i==4 and j!=0:
            q="si shi"+" "+yw(j)
            return q
        elif i == 5 and j == 0:
            return "wu shi"
        elif i==5 and j!=0:
            q="wu shi"+" "+yw(j)
            return q
        elif i == 6 and j == 0:
            return "liu shi"
        elif i==6 and j!=0:
            q="liu shi"+" "+yw(j)
            return q
        elif i == 7 and j == 0:
            return "qi shi"
        elif i==7 and j!=0:
            q="qi shi"+" "+yw(j)
            return q
        elif i == 8 and j == 0:
            return "ba shi"
        elif i==8 and j!=0:
            q="ba shi"+" "+yw(j)
            return q
        elif i == 9 and j == 0:
            return "jiu shi"
        elif i==9 and j!=0:
            q="jiu shi"+" "+yw(j)
            return q
def sw(n):
    if 999>=n>=100:
        h = n// 100
        i=n%100
        if h!=0 and i==0:
            return yw(h)+" "+"bai"
        elif h!=0 and i!=0:
            return yw(h)+" "+"bai"+" "+lw(i)
def siw(n):
    if 9999>=n>=1000:
        g=n//1000
        h=n%1000
        # i=(n%1000)%100
        # j=n%1000
        if h==0:
            return yw(g)+" "+"qian"
        elif 999>=h>=100:
            return yw(g)+" "+"qian"+" "+sw(h)
        elif 99>=h>10:
            return yw(g)+" "+"qian"+" "+"ling"+" "+lw(h)
        elif h==10:
            return yw(g)+" "+"qian"+" "+"ling"+" "+"yi"+" "+"shi"
        elif 9>=h>0:
            return yw(g)+" "+"qian"+" "+"ling"+" "+yw(h)
def ww(n):
    if 99999>=n>=10000:
        a=n//10000
        b=n%10000
        if b==0:
            return yw(a)+" "+"wan"
        elif 9999>=b>=1000:
            return yw(a)+" "+"wan"+" "+siw(b)
        elif 999>=b>=100:
            return yw(a)+" "+"wan"+" "+"ling"+" "+sw(b)
        elif 99>=b>=10:
            return yw(a)+" "+"wan"+" "+"ling"+" "+lw(b)
        elif 9>=b>0:
            return yw(a) + " " + "wan" + " " + "ling" +" "+ yw(b)
def liuw(n):
    if 999999>=n>=100000:
        a=n//100000
        b=n%100000
        if b==0and a!=1:
            return yw(a)+" "+"shi"+" "+"wan"
        elif b==0and a==1:
            return "shi"+" "+"wan"
        elif 99999>=b>=10000 and a!=1:
            return yw(a)+" "+"shi"+" "+ww(b)
        elif 99999>=b>=10000 and a==1:
            return "shi"+" "+ww(b)
        elif 9999 >= b >= 1000 and a != 1:
            return yw(a) + " " + "shi" + "wan" +" "+"ling"+" "+siw(b)
        elif 9999 >= b >= 1000 and a == 1:
            return "shi" + " " +"wan"+" "+"ling"+" "+siw(b)
        elif 999 >= b >= 100 and a != 1:
            return yw(a) + " " + "shi" + "wan" + " " + "ling" + " " + sw(b)
        elif 999 >= b >= 100 and a == 1:
            return "shi" + " " + "wan" + " " + "ling" + " " + sw(b)
        elif 99 >= b >= 10 and a != 1:
            return yw(a) + " " + "shi" + "wan" + " " + "ling" + " " + lw(b)
        elif 99 >= b >= 10 and a == 1:
            return "shi" + " " + "wan" + " " + "ling" + " " + lw(b)
        elif 9 >= b >0 and a != 1:
            return yw(a) + " " + "shi" + "wan" + " " + "ling" + " " + yw(b)
        elif 9 >= b >0 and a == 1:
            return "shi" + " " + "wan" + " " + "ling" + " " + yw(b)
def qw(n):
    if 9999999>=n>=1000000:
        a=n//1000000
        b=n%1000000
        if b==0:
            return yw(a)+" "+"bai"+" "+"wan"
        elif 999999>=b>=100000:
            return yw(a)+" "+"bai"+" "+liuw(b)
        elif 99999>=b>=10000:
            return yw(a)+" "+"bai"+" "+"ling"+" "+ww(b)
        elif 9999>=b>=1000:
            return yw(a)+" "+"bai"+" "+"wan"+" "+"ling"+" "+siw(b)
            # return yw(a) + " " + "bai" + " " + "wan"+ " " + siw(b)
        elif 999>=b>=100:
            return yw(a)+" "+"bai"+" "+"wan"+" "+"ling"+" "+sw(b)
        elif 99>=b>=10:
            return yw(a)+" "+"bai"+" "+"wan"+" "+"ling"+" "+lw(b)
        elif 9>=b>0:
            return yw(a)+" "+"bai"+" "+"wan"+" "+"ling"+" "+yw(b)
def bw(n):
    if 99999999>=n>=10000000:
        a=n//10000000
        b=n%10000000
        if b == 0:
            return yw(a) + " " + "qian" + " " + "wan"
        elif 9999999 >= b >= 1000000:
            return yw(a) + " " + "qian" + " " + qw(b)
        elif 999999 >= b >= 100000:
            return yw(a) + " " + "qian" + " " + liuw(b)
        elif 99999 >= b >= 10000:
            return yw(a) + " " + "qian" + " " + "ling" + " " + ww(b)
        elif 9999 >= b >= 1000:
            return yw(a) + " " + "qian" + " " + "wan" + " " + "ling" + " " + siw(b)
            # return yw(a) + " " + "bai" + " " + "wan"+ " " + siw(b)
        elif 999 >= b >= 100:
            return yw(a) + " " + "qian" + " " + "wan" + " " + "ling" + " " + sw(b)
        elif 99 >= b >= 10:
            return yw(a) + " " + "qian" + " " + "wan" + " " + "ling" + " " + lw(b)
        elif 9 >= b > 0:
            return yw(a) + " " + "qian" + " " + "wan" + " " + "ling" + " " + yw(b)
def jw(n):
    if 999999999>=n>=100000000:
        a=n//100000000
        b=n%100000000
        if b == 0:
            return yw(a) + " "+ "yi"
        elif 99999999 >= b >= 10000000:
            return yw(a) + " " + "yi" + " " + bw(b)
        elif 9999999 >= b >= 1000000:
            return yw(a) + " " + "yi" + " " +"ling"+" "+ qw(b)
        elif 999999 >= b >= 100000:
            return yw(a) + " " + "yi" + " " +"ling"+" "+ liuw(b)
        elif 99999 >= b >= 10000:
            return yw(a) + " " + "yi" + " " + "ling" + " " + ww(b)
        elif 9999 >= b >= 1000:
            return yw(a) + " " + "yi" + " "+"ling" + " " + siw(b)
        elif 999 >= b >= 100:
            return yw(a) + " " + "yi" + " "+"ling" + " " + sw(b)
        elif 99 >= b >= 10:
            return yw(a) + " " + "yi" + " "+"ling" + " " + lw(b)
        elif 9 >= b > 0:
            return yw(a) + " " + "yi" + " "+"ling" + " " + yw(b)
def shiw(n):
    if 9999999999>=n>=1000000000:
        a=n//1000000000
        b=n%1000000000
        if b == 0 and a!=1:
            return yw(a) + " "+"shi"+" "+ "yi"
        elif b == 0 and a==1:
            return "shi"+" "+ "yi"
        elif 999999999 >= b >= 100000000 and a!=1:
            return yw(a) + " " +"shi"+" " + jw(b)
        elif 999999999 >= b >= 100000000 and a==1:
            return "shi"+" " + jw(b)
        elif 99999999 >= b >= 10000000and a!=1:
            return yw(a) + " "+"shi"+" "+ "yi" + " "+"ling" +" "+ bw(b)
        elif 99999999 >= b >= 10000000 and a==1:
            return "shi"+" "+ "yi" + " "+"ling" +" "+ bw(b)
        elif 9999999 >= b >= 1000000 and a!=1:
            return yw(a) + " "+"shi"+" "+ "yi" + " "+"ling" +" "+ qw(b)
        elif 9999999 >= b >= 1000000 and a==1:
            return "shi"+" "+ "yi" + " "+"ling" +" "+ qw(b)
        elif 999999 >= b >= 100000and a!=1:
            return yw(a) + " "+"shi"+" "+ "yi" + " "+"ling" +" "+ liuw(b)
        elif 99999 >= b >= 10000 and a==1:
            return "shi" + " " + "yi" + " " + "ling" + " " + liuw(b)
        elif 99999 >= b >= 10000 and a!=1:
            return yw(a) + " "+"shi"+" "+ "yi" + " "+"ling" +" "+ ww(b)
        elif 99999 >= b >= 10000 and a==1:
            return "shi"+" "+ "yi" + " "+"ling" +" "+ ww(b)
        elif 9999 >= b >= 1000 and a!=1:
            return yw(a) + " "+"shi"+" "+ "yi" + " "+"ling" +" "+ siw(b)
        elif 9999 >= b >= 1000and a==1:
            return "shi"+" "+ "yi" + " "+"ling" +" "+ siw(b)
        elif 999 >= b >= 100 and a!=1:
            return yw(a) + " "+"shi"+" "+ "yi" + " "+"ling" +" "+ sw(b)
        elif 999 >= b >= 100and a==1:
            return "shi"+" "+ "yi" + " "+"ling" +" "+ sw(b)
        elif 99 >= b >= 10 and a!=1:
            return yw(a) + " "+"shi"+" "+ "yi" + " "+"ling" +" "+ lw(b)
        elif 99 >= b >= 10 and a==1:
            return "shi"+" "+ "yi" + " "+"ling" +" "+ lw(b)
        elif 9 >= b > 0 and a!=1:
            return yw(a) + " "+"shi"+" "+ "yi" + " "+"ling" +" "+ yw(b)
        elif 9 >= b > 0 and a==1:
            return "shi"+" "+ "yi" + " "+"ling" +" "+ yw(b)
if 9>=n>=0:
    print(yw(n))
elif 99>=n>=10:
    print(lw(n))
elif 999 >= n >= 100:
    print(sw(n))
elif 9999 >= n >= 1000:
    print(siw(n))
elif 99999 >= n >= 10000:
    print(ww(n))
elif 999999 >= n >= 100000:
    print(liuw(n))
elif 9999999 >= n >= 1000000:
    print(qw(n))
elif 99999999 >= n >= 10000000:
    print(bw(n))
elif 999999999 >= n >= 100000000:
    print(jw(n))
elif 9999999999 >= n >= 1000000000:
    print(shiw(n))

标签:yi,elif,return,python,蓝桥,--,ling,shi,yw
来源: https://blog.csdn.net/m0_46552988/article/details/122851429