Getting values from local variables in another procedure in Python 3.x
<p>I am currently learning how to program but I don't understand how to access a local variable from one procedure in order to use that variable's value in a different procedure. I am using Python version 3.5.2 and I have confirmed that the code will work when not divided into procedures. </p>

<pre><code>#This program will ask for the users age, weight and birth month, compare
#the input values to secret answers and return a response based on the input.

def main():
    age=0
    weight=0
    month=""

    age=float(input("What is your age? "))
    weight=float(input("What is your weight? "))
    month=input("What is your birth month? ")
    evaluate()

def evaluate():
    if age&lt;=25:
        print("Congratulations, the age is 25 or less!")
    elif weight&gt;=128:
        print("Congratulations, the weight is 128 or more!")
    elif month=='April':
        print("Congratulations, the birth month is April!")

main()
</code></pre>

<p>So just to show what the commenters said:</p>

<pre><code>def evaluate(theage, theweight, themonth):
    if theage&lt;=25:
        print("Congratulations, the age is 25 or less!")
    elif theweight&gt;=128:
        print("Congratulations, the weight is 128 or more!")
    elif themonth=='April':
        print("Congratulations, the birth month is April!")
#end of evaluate()

def main():
    # ... your existing code ...
    evaluate(age, weight, month)
</code></pre>

<p><code>evaluate()</code> goes before <code>main()</code> so that <code>main()</code> knows about <code>evaluate()</code>.  Define things first, then reference them, and you will avoid obscure problems (although, as someone will certainly point out, that's not always required).</p>

<p>The parameters to <code>evaluate</code> are listed between the <code>()</code>.  The values are then passed when <code>evaluate()</code> is called from <code>main()</code>.  I renamed the parameters to <code>evaluate()</code> to show you that the names don't have to be the same.  With the code above, <code>theage</code> in <code>evaluate()</code> gets a copy of the value of <code>age</code> in <code>main()</code>.  The same goes for <code>theweight</code> and <code>weight</code>, and for <code>themonth</code> and <code>month</code>.</p>

python python-3.x procedure local-variables