Variables reset with every recursive call so function doesn't work. (Python)
<p>Code:    </p>

counter and storage are reset every time the function is called recusively

<pre><code>def bin_to_dec(b):    
    '''Takes a string b that represents a binary number and uses recursion
       to convert the number from binary to decimal.'''
    counter = -1    
    storage = 0    
    if b == 0:   
        return '0'
    elif b == 1:
        return '1'
    else:    
        if b[-1] == 1:
            counter += 1
            storage += 2**counter
            return storage + bin_to_dec(b[:-1])
        else:
            counter += 1
            return bin_to_dec(b[:-1])
</code></pre>

<p>So I am writing a function that converts binary numbers to decimal numbers but every time the function is called recursively the variables counter and storage are reset. I must use recursion and can't use anything I haven't learned yet such as map or key. </p>

<p>Anything you want to be preserved through function calls should not be local to the function. There are many ways to preserve values between calls. The recommended way in your case is to pass it as a parameter to the function.</p>

python