#/use/bin/env python
#-*-coding:utf-8-*-
"this is a custom module"
def number_to_english(num):
'''
输入一个整数值,返回代表该值得英文,数字限定在0---1000
'''
number_0_10 = ['zero','one','two','three','four','five','six','seven','eight','nine','ten']
number_11_19 = ['eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']
number_20_100 = ['twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety','hundred']
number = int(num)
transfer = ""
if number < 0 or number > 1000:
return transfer
if number == 0:
transfer = number_0_10[0]
return transfer
if number == 1000:
transfer = "one-thousand"
return transfer
if number <= 10:
transfer = number_0_10[number]
return transfer
elif number > 10 and number <= 20:
index = number % 10
index -= 1
transfer = number_11_19[index]
return transfer
hundred_digit = number / 100
ten_digit = number % 100 / 10
single_digit = number % 100 % 10
connect_word = ""
if hundred_digit > 0:
transfer = number_0_10[hundred_digit]
transfer += "-hundred"
connect_word = " and "
if ten_digit > 0:
if connect_word not in "":
transfer += connect_word
transfer += number_20_100[ten_digit - 2]
else:
if ten_digit == 1:
index = single_digit - 1
if index < 0:
transfer = 'ten'
else:
transfer = number_11_19[index]
return transfer
else:
transfer = number_20_100[ten_digit - 2]
if single_digit > 0:
if ten_digit > 0:
transfer += '-'
transfer += number_0_10[single_digit]
else:
if hundred_digit > 0:
transfer += connect_word
transfer += number_0_10[single_digit]
return transfer
if __name__ == '__main__':
print number_to_english(342)
print number_to_english(89)
print number_to_english(7)
print number_to_english(18)
print number_to_english(200)
print number_to_english(506)
print number_to_english(1000)
print number_to_english(2000)
print number_to_english(100)
print number_to_english(999)