# Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 2.32 KB  |  views: 22  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. listOnesPlace = 'one two three four five six seven eight nine'.split()
2. listTensPlace = 'twenty thirty forty fifty sixty seventy eighty ninety'.split()
3. listTeens = 'ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen'.split()
4. listMagnitudes = 'thousand million billion trillion quadrillion quintillion sextillion septillion octillion nonillion decillion undecillion duodecillion trececillion quattuordecillion quindecillion'.split()
5.
6. def takeBiggestChunk(strNum):
7.     mag = 0
8.     strBig = strNum
9.     while len(strBig) > 3:
10.         strBig = strBig[:len(strBig)-3]
11.         mag += 1
12.     strSmall = strNum[len(strNum)-3*mag:]
13.     return strBig, strSmall, mag
14.
15. def printNumber(strNum):
16.     strWords = []
17.     strSmall = strNum
18.
19.     while True:
20.         strBig, strSmall, mag = takeBiggestChunk(strSmall)
21.         if mag == 0:
22.             break
23.         strWords += hundreds(strBig)
24.         strWords += ' '
25.         strWords += listMagnitudes[mag-1]
26.         strWords += ', '
27.
28.     strWords += hundreds(strBig)
29.
30.     return ''.join(strWords)
31.
32. def hundreds(strNum):
33.     strWords = []
34.     if len(strNum) == 3 and strNum[0] != '0':
35.         strWords += listOnesPlace[int(strNum[0])-1]
36.         strWords += ' hundred '
37.     strWords += tensAndOnes(strNum[len(strNum)-2:len(strNum)])
38.     return ''.join(strWords)
39.
40. def tensAndOnes(strNum):
41.     strWords = []
42.     if len(strNum) == 1 or strNum[0] == '0':
43.         strWords += listOnesPlace[int(strNum[0])-1]
44.     else:
45.         if strNum[0] == '0':
46.             strWords += listOnesPlace[int(strNum[1])-1]
47.         elif strNum[0] == '1':
48.             strWords += listTeens[int(strNum[1])]
49.         else:
50.             strWords += listTensPlace[int(strNum[0])-2]
51.             if strNum[1] != '0':
52.                 strWords += '-'
53.                 strWords += listOnesPlace[int(strNum[1])-1]
54.     return ''.join(strWords)
55.
57.     print('Hello! Please enter a number.')
58.     while True:
59.         number = input()
60.         if number.isdigit():
61.             return number
62.         else:
63.             print('Please enter any number from 1 to 99, in numerical form.')
64.
65. def promptRestart():
66.     print('Restart? (y/n)')
67.     return input().lower().startswith('y')
68.
69. while True: