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 else: mid = avg(x[len(x) // 2 - 1], x[len(x) // 2]) return mid a = [1,2,3,4,5,6,7] print median(a)