fork download
  1. def countLetter(n):
  2. p=['','One','Two','Three','Four','Five','Six','Seven','Eight','Nine']
  3. q=['','Ten','Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety']
  4. r=['','Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Nineteen']
  5.  
  6. c=str(n)
  7. l=len(c)
  8. a=""
  9.  
  10. if l==1:
  11. a+=p[int(c[0])]
  12. elif l==2:
  13. if c[1]=='0':
  14. a+=q[int(c[0])]
  15. elif c[0]=='1':
  16. a+=r[int(c[1])]
  17. else:
  18. a+=q[int(c[0])]+p[int(c[1])]
  19. elif n==100:
  20. a+="OneHundred"
  21. elif l==3:
  22. a+=p[int(c[0])]+"Hundred"
  23. if c[1]=='0' and c[2]=='0':
  24. a+=""
  25. elif c[2]=='0' and c[1]!='0':
  26. a+="And"+q[int(c[1])]
  27. elif c[1]=='1':
  28. a+="And"+r[int(c[2])]
  29. else:
  30. a+="And"+q[int(c[1])]+p[int(c[2])]
  31. else:
  32. a+="OneThousand"
  33.  
  34. #print a,len(a)
  35. return len(a)
  36.  
  37. def main():
  38. sum=0
  39. for i in range(1,1001):
  40. sum+=countLetter(i)
  41. print sum
  42.  
  43. main()
  44.  
Success #stdin #stdout 0.01s 7852KB
stdin
Standard input is empty
stdout
21124