Conversion of integers to Roman numerals (python)
<p>I understand there were many similar questions being asked on this topic. But I still have some doubts need to be clear.</p>

<pre><code>def int_to_roman(input):

    if type(input) != type(1):
        raise TypeError, "expected integer, got %s" % type(input)
    if not 0 &lt; input &lt; 4000:
        raise ValueError, "Argument must be between 1 and 3999"   
    ints = (1000, 900,  500, 400, 100,  90, 50,  40, 10,  9,   5,  4,   1)
    nums = ('M',  'CM', 'D', 'CD','C', 'XC','L','XL','X','IX','V','IV','I')
    result = ""
    for i in range(len(ints)):
        count = int(input / ints[i])
        result += nums[i] * count
        input -= ints[i] * count
    return result
</code></pre>

<p>I dont really understand the code below:</p>

<pre><code>for i in range(len(ints)):
    count = int(input / ints[i])
    result += nums[i] * count
    input -= ints[i] * count
</code></pre>

<p>Does:</p>

<pre><code>for i in range (len(ints)):
</code></pre>

<p>it means '1000','900','800' (the integers respectively) or it means 13 (13 integers in integers)?</p>

<pre><code>count = int(input / ints[i])
</code></pre>

<p>what does ints [i] mean?</p>

<p>Anyone please explain these codes? It would be best if you could show the examples (like substitute numbers and show how it works)</p>

<p>The names of the two lists are awful (<code>ints</code> and <code>nums</code>).  </p>

<p>However, starting with the highest roman numeral (<code>nums[0]</code> = 'M'), the loop finds out how many times the value of that numeral (<code>ints[0]</code> = 1000) divides into the input value, and appends the numeral that many times to the result string.   </p>

<p>Then it subtracts the value of that string just added to the result (<code>ints[0] * count</code>) from the input, and moves on to the next roman numeral (<code>nums[1]</code>) to repeat the process with that remainder.</p>

python python-2.7 function roman-numerals