list Index error on "Risk" dice game
<p>I'm trying to make a function that gives the win/loss ratio of a roll of number of dice in the game of Risk.</p>

<p>For those who don't know, in Risk there's an attacker and defender where the attackers maximum die is compared to maximum die of the defender, and this repeats for each pair of dice until the defender no longer has dice left. If the attacker wins, the defender loses 1 army, and if the defenders die is equal or greater, the attacker loses 1 army.</p>

<p>So if I run the code I should get</p>

<pre><code>result([1, 4, 5], [3, 2])

(0, -2)
</code></pre>

<p>where the attacker lost two because 5>3 and 4>2.</p>

<p>When I try and run my code, I get a list index error, any help in fixing the error is greatly appreciated. </p>

<pre><code>def result(n,m):
    first=0
    second=0
    n=(sorted(n))[::-1]
    m=(sorted(m))[::-1]
    while len(n)&gt;len(m):
        n = n[:-1]
    while True:
        for i in m:
            if n[i] &gt; m[i]:
                second -= 1
            elif n[i] &lt;= m[i]:
                first -= 1
            else:
                break
    return (first,second)
</code></pre>