Python: Call a variable from a function to an if statement
<p>I am trying to practice my modular programming with this assignment. I found out how to call the variables into my main function, but for my if statement in evenOdd(), I am not sure how to call the value. I get the error 'randNum' is not defined.</p>

<pre><code>from random import randint
def genNumber():
    randNum = randint(0,20000)
    print("My number is " + str(randNum))
    return (randNum)

def inputNum():
    userNum = input("Please enter a number: ")
    print("Your number is " + str(userNum))
    return (userNum)

def evenOdd():
    if randNum%2==0:
        print("My number is even")
    else:
        print("My number is odd")
    if userNum%2==0:
        print("Your number is even")
    else:
        print("Your number is odd")

def main():
    randNum = genNumber()
    userNum = inputNum()
    evenOdd()
    input("Press ENTER to exit")


main()
</code></pre>

<p>You can either define randNum in the global scope or just pass it as a variable to your evenOdd() function, like this evenOdd( randNum ).</p>

python function variables