Skip to content

Instantly share code, notes, and snippets.

@KorbenC
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save KorbenC/9901625 to your computer and use it in GitHub Desktop.

Select an option

Save KorbenC/9901625 to your computer and use it in GitHub Desktop.
Print out the text form of numbers from 1 - 1000(eg 20 is "twenty")
#!/usr/bin/env python
import sys
map = {
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:'fourty',
50:'fifty',
60:'sixty',
70:'seventy',
80:'eighty',
90:'ninety',
100:'hundred'
}
def word_numbers(input):
try:
print map[input]
except KeyError:
try:
print map[input-input%10] + map[input%10].lower()
except KeyError:
print 'Number out of range'
def main():
for n in xrange(1,100):
word_numbers(n)
if __name__ == '__main__':
status = main()
sys.exit(status)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment