Python converts Arabic numerals into uppercase letters

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.