+ 2
Please, explain what is the error in my python code to return the median of a list with integers?
if list has even no of elements,it should return the average of 2 middle numbers. def median(A): A=A.sort() l=len(A) c=int(l/2) if(l%2!=0): return(A[c]) else: return((A[c]+A[c-1])/2) print(median([1,3,7,9,2])) print(median([2,4,5,1]))
3 Respostas
+ 3
If statements don't have parentheses. The line should be:
if l%2!=0:
# statements
+ 3
Oh. (im embarrassed because i've already made 2 mistakes today)
+ 1
@ace thanks sir,I got it now,🙏