simples = {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"} tens = {2:"Twenty", 3:"Thirty", 4:"Forty", 5:"Fifty",\ 6:"Sixty", 7:"Seventy", 8:"Eighty", 9:"Ninety"} hundreds = "Hundred" thousand = "Thousand" def verbose(x): result = "" if x//1000: result += simples[x//1000]+thousand x = x%1000 if x//100: result += simples[x//100]+hundreds x = x%100 if x: result += "And" if x//10>1: result += tens[x//10] x = x%10 if x: result += simples[x] return result def count_letters(x): word = verbose(x) return len(word) #print verbose(342) #print count_letters(342) total = 0 for i in range(1,1001): total += count_letters(i) print total
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question