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>Pass it as a parameter</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(guesses)

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

<p>Passing inputs as parameters, and using <code>return</code> to pass variables out as outputs allows you to control the flow of data in your program and not use <code>global</code> variables as a crutch.</p>

python