Last active
August 29, 2015 13:57
-
-
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")
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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