Skip to content

Instantly share code, notes, and snippets.

@dannyroa
Created January 29, 2013 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannyroa/4662418 to your computer and use it in GitHub Desktop.
Save dannyroa/4662418 to your computer and use it in GitHub Desktop.
def get_val():
words = { 1 : 'one', 2 : 'two', 3 : 'three', 4 : 'four', 5 : 'five', 6 : 'six', 7 : 'seven'
, 8 : 'eight', 9 : 'nine', 10 : 'ten', 11 : 'eleven', 12 : 'twelve', 13 : 'thirteen'
, 14 : 'fourteen', 15 : 'fifteen', 16 : 'sixteen', 17 : 'seventeen', 18 : 'eighteen'
, 19 : 'nineteen', 20 : 'twenty', 30 : 'thirty', 40 : 'forty', 50 : 'fifty', 60 : 'sixty'
, 70 : 'seventy', 80 : 'eighty', 90 : 'ninety', 100 : 'hundred', 1000 : 'thousand' }
word_length = 0
for num in range(1, 1001):
print num
temp_num = num % 100
end_word = ''
if temp_num > 0:
if temp_num < 20:
end_word = words[temp_num]
else:
end_word = words[(temp_num / 10) * 10]
if temp_num % 10 > 0:
end_word += words[temp_num % 10]
num = num - temp_num
#print ' %s' % num
num_length = len(str(num))
num_word = ''
for i in range(num_length - 2):
multiplier = 10 ** (num_length - i - 1)
#print 'multiplier: %s' % multiplier
if (num / multiplier) > 0:
num_word = words[num / multiplier] + words[multiplier] + num_word
#print ' %s' % num
#print ' %s' % num_word
num = num % multiplier
if num_word and end_word:
num_word = '%sand%s' % (num_word, end_word)
else:
num_word = '%s%s' % (num_word, end_word)
print '*** %s' % num_word
word_length += len(num_word)
return word_length
print get_val()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment