title: Numbers To Words in Python
body: <p>I want write a program that accepts an integer between 1 and 9999 (inclusive) and prints the value in words. For example, if the user enters:</p>
  
  <blockquote>
    <p>3421</p>
  </blockquote>
  
  <p>then the program should print:</p>
  
  <pre><code>three thousand four hundred twenty one
  </code></pre>
  
  <p>My code is below, but it doesn't work.</p>
  
  <pre><code>num=int(input('please enter an integer between 1 and 9999: '))
  
  def int_to_en(num):
      d = { 0 : 'zero', 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 : 'ninteen', 20 : 'twenty', \
            30 : 'thirty', 40 : 'fourth', 50 : 'fifty', 60 : 'sixty', \
            70 : 'seventy', 80 : 'eighty', 90 : 'ninty' }
      k = 1000
      m = k * 1000
  
      if (num &lt; 20):
          print(d[num])
  
      if (num &lt; 100):
          if num % 10 == 0:
              print(d[num])
          else:
              print(d[num // 10 * 10] + '' + d[num % 10])
  
      if (num &lt; k):
          if num % 100 == 0:
              print(d[num // 100] + ' hundred')
          else:
              print(d[num // 100] + ' hundred ' + int_to_en(num % 100))
  
      if (num &lt; m):
          if num % k == 0:
              print(int_to_en(num // k) + ' thousand')
          else:
              print(int_to_en(num // k) + ' thousand, ' + int_to_en(num % k))
  </code></pre>