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>I think this is what you are trying to achieve.</p>

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

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

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

<p>You need to use <code>global</code> expression in order to overwrite the global variable without a need to create <code>return</code> inside the function and typing <code>a = read()</code>. </p>

<p>But I would <strong>highly</strong> recommend u to <strong>use</strong> the <code>return</code> and re-assigned the value of 'a', as someone stated below.</p>

python variables