Question about the return


Hi Guys, I am confused that why sometime I need to return the value for printing, sometime it is unnecessary to use the return.
Fox example, please review the below code, first I have not used "return" to print the value, but I found that the code return None.
So I added "return" in the code, and it works.
Why I have to use "return" as I though mid had assigned a value, so the program should print the value without return.

def avg(a,b):
    avg = 0
    avg = (a + b) / 2.0
    return avg
    def median(x):
        x = sorted(x)
        mid = 0
        if len(x) % 2 > 0:
            mid = x[len(x) // 2]
            return mid
            mid = avg(x[len(x) // 2 - 1], x[len(x) // 2])
            return mid

    a = [1,2,3,4,5,6,7]
    print median(a)


CC really enjoys returns, just accept it and it will be kind to you :wink:


haha, but what is CC?


short for Code-Cademy. :slight_smile:


= =
alright, so if I use the python program, it is not a problem anymore?


Correct. I don't use returns for my average everyday programming, but I'm not sure for upper level progams.


got it, thanks man.
keep learning, this unit took me about 7 hrs to finish :sob: