Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- listOnesPlace = 'one two three four five six seven eight nine'.split()
- listTensPlace = 'twenty thirty forty fifty sixty seventy eighty ninety'.split()
- listTeens = 'ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen'.split()
- listMagnitudes = 'thousand million billion trillion quadrillion quintillion sextillion septillion octillion nonillion decillion undecillion duodecillion trececillion quattuordecillion quindecillion'.split()
- def takeBiggestChunk(strNum):
- mag = 0
- strBig = strNum
- while len(strBig) > 3:
- strBig = strBig[:len(strBig)-3]
- mag += 1
- strSmall = strNum[len(strNum)-3*mag:]
- return strBig, strSmall, mag
- def printNumber(strNum):
- strWords = []
- strSmall = strNum
- while True:
- strBig, strSmall, mag = takeBiggestChunk(strSmall)
- if mag == 0:
- break
- strWords += hundreds(strBig)
- strWords += ' '
- strWords += listMagnitudes[mag-1]
- strWords += ', '
- strWords += hundreds(strBig)
- return ''.join(strWords)
- def hundreds(strNum):
- strWords = []
- if len(strNum) == 3 and strNum[0] != '0':
- strWords += listOnesPlace[int(strNum[0])-1]
- strWords += ' hundred '
- strWords += tensAndOnes(strNum[len(strNum)-2:len(strNum)])
- return ''.join(strWords)
- def tensAndOnes(strNum):
- strWords = []
- if len(strNum) == 1 or strNum[0] == '0':
- strWords += listOnesPlace[int(strNum[0])-1]
- else:
- if strNum[0] == '0':
- strWords += listOnesPlace[int(strNum[1])-1]
- elif strNum[0] == '1':
- strWords += listTeens[int(strNum[1])]
- else:
- strWords += listTensPlace[int(strNum[0])-2]
- if strNum[1] != '0':
- strWords += '-'
- strWords += listOnesPlace[int(strNum[1])-1]
- return ''.join(strWords)
- def askForNumber():
- print('Hello! Please enter a number.')
- while True:
- number = input()
- if number.isdigit():
- return number
- else:
- print('Please enter any number from 1 to 99, in numerical form.')
- def promptRestart():
- print('Restart? (y/n)')
- return input().lower().startswith('y')
- while True:
- print (printNumber(askForNumber()))
- if not promptRestart():
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement