title: Function to convert a decimal into that of any base
body: <p>I am doing this question via an Online learning platform, and there are test cases assigned which i must pass. <strong>The topic is Higher Order Functions.</strong></p>
  
  <p>Here is the question:</p>
  
  <p><strong>Write a function make_decimal_to_n_ary_converter that accepts a number n where 1 &lt; n &lt; 17, and returns a number converter that converts a given decimal number into that of base n.</strong></p>
  
  <p><strong>Below is my code</strong>(I am supposed to use an inner function i.e converter(x))</p>
  
  <pre><code>    def make_decimal_to_n_ary_converter(n):
      def converter(x):
          if x==0 or x==1:   
              return x
          i=x
          b=('A','B','C','D','E','F')
          result = ""
          while i&gt;0:
              a=i%n          #3
              if a&lt;10:
                  result = str(i%n)+result
              else:
                  d=a-10
                  result = b[d] + result
              i=i//n
  
          return result
      return converter
  
  #Lines below are not to be changed, part of qn
  decimal_to_binary = make_decimal_to_n_ary_converter(2)
  decimal_to_octal = make_decimal_to_n_ary_converter(8)
  decimal_to_hexadecimal = make_decimal_to_n_ary_converter(16)
  </code></pre>
  
  <p><strong>Here are some test cases that my code passes:</strong></p>
  
  <p>decimal_to_binary(213)<br>
  11010101<br>
  decimal_to_octal(213)<br>
  325<br>
  decimal_to_hexadecimal(213)<br>
  D5<br>
  make_decimal_to_n_ary_converter(15)(213)<br>
  E3</p>
  
  <p>However, my code fails some private test cases, and feedback that i received was that my logic in the while loop is wrong. However, after printing some numbers, i failed to see anything wrong. 
  Would appreciate any help, thank you!</p>