How to use a variable from main in another function?
<p>In the following code how to I make the variable 'guesses' available to me in the 'end' function. Whenever I try this I just receive a guesses is not defined. In the play function I am returning a number and if I understand correctly than that number should be equal to 'guesses', and for a reason I don't understand 'guesses' won't work in 'end'. </p>

<pre><code>def main():
    guesses = play()
    play_again = again()
    while (play_again == True):
        guesses = play()
        play_again = again()
        total_games = 1
        total_games += 1
    end()


def end():
    print("Results: ")
    print("Total: " + print(str(guesses + 1)))
</code></pre>

<p><code>main()</code> and <code>end()</code> are two separate functions with separate scopes. You defined the variable <code>guesses</code> inside the function <code>main()</code>. It will not be available to <code>end()</code>, because the scope in which <code>end()</code> was defined did not have access to <code>guesses</code>. This is despite the fact that <code>end()</code> is called within <code>main()</code>. The inside of the function isn't aware that <code>guesses</code> exists when <code>end()</code> was created/defined.</p>

<p>The need to pass information between two functions as you are trying to do highlights the need for a very common programming paradigm regarding data flow. You can pass information into a function through the use of "parameters" or "arguments". These are variables that are defined or set when a function is called.</p>

<p>In python, they look like this:</p>

<pre><code>def function(argument):
    #do something with argument
    print (argument)
</code></pre>

python