Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
import string
digits ={1:"one",2:"two",3:"three",4:"four",5:"five",
6:"six",7:"seven",8:"eight",9:"nine"}
tens={1:"ten",2:"twenty",3:"thirty",4:"fourty",5:"fifty",
6:"sixty",7:"seventy",8:"eighty",9:"ninty"}
special={11:"eleven",12:"twelve",13:"thirteen",14:"fourteen",15:"fifteen",
16:"sixteen",17:"seventien",18:"eighteen",19:"nineteen"}
order={1:"ten",2:"hundert",3:"thousand",4:"tentousand",5:"hundret tousand"}
result = []
tens_counter= 0
number=''
while not number.isdigit():
number = raw_input("Enter a number:")
n=int(number)
while n > 0:
print "n = %d" % n
# special 11..19
if tens_counter == 0:
last_two_digits = n % 100
if last_two_digits in special.keys():
print special[last_two_digits]
result.append(special[last_two_digits])
n = n/100
tens_counter += 2
continue
# normal
digit = n % 10
if tens_counter == 0:
print digits[digit]
result.append(digits[digit])
elif tens_counter == 1:
print tens[digit]
result.append(tens[digit])
elif tens_counter >=2:
print digits[digit]+"-"+ order[tens_counter]
result.append(digits[digit]+"-"+ order[tens_counter])
n = n / 10
tens_counter += 1
#print result
result.reverse()
#print result
print "The Result is: %s" % string.join(result)
import string
digits ={1:"one",2:"two",3:"three",4:"four",5:"five",
6:"six",7:"seven",8:"eight",9:"nine"}
tens={1:"ten",2:"twenty",3:"thirty",4:"fourty",5:"fifty",
6:"sixty",7:"seventy",8:"eighty",9:"ninty"}
special={11:"eleven",12:"twelve",13:"thirteen",14:"fourteen",15:"fifteen",
16:"sixteen",17:"seventien",18:"eighteen",19:"nineteen"}
order={1:"ten",2:"hundert",3:"thousand",4:"tenthousand",5:"hundret tousand"}
result = []
tens_counter= 0
number=''
while not number.isdigit():
number = raw_input("Enter a number:")
n=int(number)
while n > 0:
print "tens_counter = %d" % tens_counter
print "n = %d" % n
# special 11..19
if tens_counter == 0:
last_two_digits = n % 100
if last_two_digits in special.keys():
print special[last_two_digits]
result.append(special[last_two_digits])
n = n/100
tens_counter += 2
continue
# normal
digit = n % 10
print "digit = %d" % digit
if tens_counter == 0:
if digit != 0:
print digits[digit]
result.append(digits[digit])
elif tens_counter == 1:
if digit != 0:
print tens[digit]
result.append(tens[digit])
elif tens_counter >=2:
if digit != 0:
print digits[digit]+"-"+ order[tens_counter]
result.append(digits[digit]+"-"+ order[tens_counter])
n = n / 10
tens_counter += 1
#print result
result.reverse()
#print result
print "The Result is: %s" % string.join(result)
from __future__ import division
import string
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 ", 1000000:"Million ",
1000000000:"Billion " }
def cword(num,decAsLongWord=False,allowZero=False):
ww = ''
if num == 0:
return (allowZero and "Zero " or "")
ltp = num
keys = words.keys()
keys.sort(reverse=True)
for key in keys:
if ltp >= key:
if key >= 100:
ww += cword(ltp//key) + words[key]
ltp = ltp - (ltp//key * key)
else:
ww += words[key]
ltp = ltp - key
if ltp < 1 and ltp > 0: #decimal handling
ww += "point "
ltpd = str(num)[int(str(num).index(".")) + 1:] #math gives rounding errors, so string manipulation to get decimal
if decAsLongWord:
for digit in range(len(ltpd)):
if ltpd[digit] == "0":
ww += cword(int(ltpd[digit]),allowZero=True)
else:
break
ww += cword(int(ltpd),allowZero=True)
else:
for digit in range(len(ltpd)):
ww += cword(int(ltpd[digit]),allowZero=True)
break
return ww
def isFloat(s):
try: float(s)
except (ValueError, TypeError): return False
else: return True
#example usage
number=''
while not isFloat(number):
number = raw_input("Enter a number:")
print cword(float(number))
print cword(float(number),decAsLongWord=True)