Recursive if-statement python
<p>Hi I am new to python and trying to implement a recursive function which fills up a table, but when running by program I get the following exception</p>

<blockquote>
  <p>unsupported operand type(s) for +: 'NoneType' and 'int'.</p>
</blockquote>

<pre><code>def cost(i, j):
    if table[i][j] == None:
        v1 = v2 = v3 = v4 = None
        if i &gt; 0 and j &gt; 0:
            print "case1"
            v1 = cost(i-1, j-1) + getSubCostMatrixValue(options[string1[i]], options[string2[j]])
        if i &gt; 0 and j &gt;= 0:
            print "case2"
            v2 = cost(i-1, j) + gapCost
        if i &gt;= 0 and j &gt; 0:
            print "case3"
            v3 = cost(i, j-1) + gapCost
        if i == 0 and j == 0:
            print "case4"
            v4 = 0
        print "Max:"
        print max(v1,v2,v3,v4)
        table[i][j] = max(v1,v2,v3,v4)
        return table[i][j]
</code></pre>

<p>the problem ocours i case 2 and case 3, as if the recursive call fails somehow, but i cannot find out why. I feel like it is something obvious </p>

<p>table is filled with None from the begining, gabCost is a int, getSubCostMatrixValue also returns an int.</p>

<p>Apparently, your <code>cost()</code> function returns <code>None</code> for some cases. If I understand right, then this can only happen if i or j are negative. As this only occurs in cases 2 or 3, it seems to me, that your i or j are indeed floats which can be larger than 0 but smaller than 1. Could this be the case? If you provide more details on your program, someone might have a more detailed answer!?</p>

python if-statement recursion