How do I transfer varibles through functions in Python
<p>I am trying to read from keyboard a number and validate it</p>

<p>This is what I have but it doesn't work. </p>

<p>No error but it doesn't <strong>remember</strong> the number I introduced</p>

<pre><code>def IsInteger(a):
    try:
        a=int(a)
        return True
    except ValueError:
        return False 

def read():
    a=input("Nr: ")
    while (IsInteger(a)!=True):
        a=input("Give a number: ")

a=0
read()
print(a)
</code></pre>

<p><code>a</code> is a local variable to the two functions and isn't visible to the rest of your code as is.  The best way to fix your code is by returning <code>a</code> from your <code>read()</code> function.  Also, the spacing is off in your <code>IsInteger()</code> function.</p>

<pre><code>def IsInteger(b):
    try:
        b=int(b)
        return True
    except ValueError:
        return False 

def read():
    a=input("Nr: ")
    while not IsInteger(a):
        a=input("Give a number: ")
    return a

c = read()
print(c)
</code></pre>

python variables