'NameError' in Python Program
<p>I'm working on a program at school and got into this problem that really screwed around with me, probably because I'm rather nooby at Python and Programming itself.</p>

<p>Anyway, here is the section of code that caused the problem:</p>

<pre><code># A function used to determine a 'try' and 'except' loop for an input of a integer data type. It also adds boundaries for the integer variables in this program        
def tryAndExceptInputInt(text):
while True:
    try:
        variable = int(input(text))
        if variable == speedLimit:
            if variable &gt; 120 or variable &lt; 5:
                raise ValueError("Please input a suitable speed limit")
            else:
                break
        elif variable == distance:
            if variable &lt; 1:
                raise ValueError("Please input a suitable distance")
            else:
                break
        elif variable == vehicles:
            if variable &lt;= 0:
                raise ValueError("Please input a valid number of vehicle(s)")
            else:
                break  
        elif variable == time1 or variable == time2:
            if len(variable) != 4:
                raise ValueError("Please input a suitable entrance/leaving time")
            else:
                variable = int(variable)
                if variable &gt;= 2400 or variable &lt; 0000:
                    raise ValueError("Please input a suitable entrance/leaving time")
                else:
                    break
        else:
            break
    # This statement keeps looping until the user inputs the suitable data type
    except ValueError:
        print("Please input a value which is an integer\n")
    else:
        return variable

# MAIN PROGRAM


# A function made to loop 'try' and 'except' so that the user's input would be the desired data type as well as variable
speedLimit = tryAndExceptInputInt("Enter the speed limit in the monitored area (mph): ")
</code></pre>

<p>Here is the Error Message I received for running this part of code:</p>

<pre><code>"In 'tryAndExceptInputInt', 'if variable == speedLimit:', NameError: name 'speedLimit' is not defined
</code></pre>

<p>Can someone answer me with a correct version of the 'tryAndExceptInputInt' function I created, Thanks ;-) </p>