Python error that shouldn't be happening : <p>my friend is getting an error that should not be happening. 
He added a variable to the top of his file, and can't access the variable from a function in his script without getting an error. </p>

<p>this is his code:</p>

<pre><code>numbers = [23, 5, 12, 94, 5 , 43, 23, 59, 10, 59, 31]
largest = 0
def find_largest(x): 
    for num in x:
        if num &gt; largest:
            largest = num
    return largest
max_number = find_largest(numbers)
print(max_number)
</code></pre>

<p>this is the error</p>

<pre><code>error message: Traceback (most recent call last):
 File "largestElement.py", line 10, in &lt;module&gt;
   max_number = find_largest(numbers)
 File "largestElement.py", line 6, in find_largest
   if num &gt; largest:
UnboundLocalError: local variable 'largest' referenced before assignment
</code></pre>

<p>why is this happening? when we move the variable definition to the function scope it works, but when we put the variable definition in the top of the script, he gets a called before reference error. Also, the numbers array doesn't have an issue and we are using it in the same way. </p>

<p>Could it maybe be something wrong with his conda environment?</p>
