How to avoid to manually set the initial value of a variable in a recursive function?
<p>I found this solution for the Euler project 5 (What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?) with a variable range of integer values to divide evenly by: </p>

<pre><code>def Euler5(start, end, counter):
    x = counter
    while start &lt;= end:
        if x%counter == x%start:
            return Euler5(start+1, end, x)
        else:
            x += counter
    return x
</code></pre>

<p>I do however have to manually set the counter to the smallest integer value (initial <code>counter</code> = <code>start</code> value). Is there a way to automatically do this and to maintain the algorithm?</p>

<p>If I understood you right, you want that <code>counter == start</code> for the initial call without specifying the <code>counter</code> manually in the first call.</p>

<p>For this, you can set <code>counter</code> to a default value of <code>None</code> and check for this at the beginning of the function, setting <code>counter</code> to the appropriate value if this is the case:</p>

<pre><code>def Euler5(start, end, counter=None):
    if counter is None:
        counter = start

    x = counter
    while start &lt;= end:
        if x % counter == x % start:
            return Euler5(start+1, end, x)
        else:
            x += counter
    return x
</code></pre>

python