Python: how to print a variable inside a defined function separately?
Question: I want to know how to print a variable inside a function, with python, for
example:

    
    
    import math
    def number():
        print
        number_enters = input("Please enter the number: ")
        square_roots = math.sqrt(number_enters)
        print square_roots
    

But how can I print the square_roots separately, like print it at the end of
the program(after other functions) for example:

    
    
    import math
    def number():
        print
        number_enters = input("Please enter the number: ")
        square_roots = math.sqrt(number_enters)
        print square_roots
    
    def bla_bla():
        .....
        .....
    
    .......
    .......
    print square_roots
    

I hope that make sense, please help me out, how can I print square_roots after
all of that?


Answer: Replace `print square_roots` with `return square_roots` in the function. This
will allow you to use the variable later.

    
    
    def number():
        print
        number_enters = input("Please enter the number: ")
        square_roots = math.sqrt(number_enters)
        return square_roots
    

Then you can store the result in a variable and then print it.

    
    
    square_root = number()
    .....
    .....
    print square_root
    

