Python converts Arabic numerals to Chinese numerals in uppercase and converts Arabic numerals to Chinese numerals in uppercase. In fact, the most troublesome thing is the problem of multiple zeros in the middle. in this case, the sharding rule is adopted, split a large number into an integer part and a decimal part, and split the integer part into a List consisting of four strings according to the minute, tens of thousands, hundreds of millions, and megabytes, each string can contain a maximum of 4 characters, and then converts the string of each sub-digit into uppercase and merges the strings. this reduces the problem and simplifies the processing.
#! /Usr/bin/env python #-*-coding: UTF-8-*-''' # algorithm description: string input is required, the string difference fee is the integer part and the decimal part to generate the list [integer part, decimal part] # Split the integer part into a List consisting of three strings: [, and digits: ['123', '123', '123'] (generate a tiered List based on actual input) # for example, split the integer part 0000 into ['123', '123 ', '000000'] # uppercase and then merge each string group in the list # final processing of the decimal part is capitalized ''' class cnumber: cdict ={} gdict ={} xdict ={} def _ init _ (self): self. cdict = {1: u'', 2: u'pick', 3: u'hangzhou', 4: u'hangzhou'} self. xdict = {1: u 'Yuan ', 2: u 'wan', 3: u '100 ', 4: u 'MB'} # digital identifier self. gdict = {0: u '0', 1: u 'yi', 2: u 'ER', 3: u 'san', 4: u 'Si ', 5: u'wo', 6: u'lu', 7: u'hangzhou', 8: u'hangzhou', 9: u'hangzhou'} def csplit (self, cdata): # Split the integer string into list g = len (cdata) % 4 csdata = [] lx = len (cdata) of [, Hangzhou) -1 if g> 0: csdata. append (cdata [0: g]) k = g while k <= lx: csdata. append (cdata [k: k + 4]) k + = 4 return csdata def cschange (self, cki): #, then merge lenki = len (cki) I = 0 lk = lenki chk = u'' for I in range (lenki ): if int (cki [I]) = 0: if I