数字分为 000(billion),000(million),000(thound),000 四段,
three_digit 函数输出每一段的表达,function函数把四段链接起来
def three_digit(string):
dic1 = {'1':'one','2':'two','3':'three','4':'four','5':'five','6':'six','7':'seven','8':'eight','9':'nine'}
dic2 = {'10':'ten','11':'eleven','12':'twelve','13':'thirteen','14':'fourteen','15':'fifteen','16':'sixteen','17':'seventeen','18':'eighteen','19':'nineteen'}
dic3 = {'2':'twenty','3':'thirty','4':'forty','5':'fifty','6':'sixty','7':'seventy','8':'eighty','9':'ninety'}
result = ''
if string[0] != '0':
result = dic1[string[0]] + ' hundred '
if string[1:] != '00':
result += 'and '
if string[1] == '1':
result += dic2[string[1:]] + ' '
if string[1] != '1' and string[1] != '0':
result += dic3[string[1]] + ' '
if string[1] != '1' and string[2] != '0':
result += dic1[string[2]] + ' '
return result
def function(string):
number = string.rjust(12,'0')
result = ''
if number[0:3] != '000':
result = three_digit(number[0:3]) + 'billion '
if number[3:6] != '000':
result = result + three_digit(number[3:6]) + 'million '
if number[6:9] != '000':
result = result + three_digit(number[6:9]) + 'thousand '
if number[9:12] != '000':
result = result + three_digit(number[9:12])
return result
while True:
try:
print(function(input()))
except:
break


京公网安备 11010502036488号