Not sure I follow


not sure I follow...

"If the list contains an even number of elements, your function should return the average of the middle two."

I got the error: "Oops, try again. median([4, 5, 5, 4]) returned 5 instead of 4.5"

So... would the average of five and five not be five?


def median(seqq):
	length = len(seqq)
	if length % 2 == 0:
		answer = (seqq[(length/2)-1] + seqq[length/2]) / 2
		nub = length/2
		answer = seqq[nub]
	return answer

Bug in "Median" lesson?

try add 0.5 in the end of line4,though it's cheating


A median is always plotted on a sorted sample space. Samples are grouped in order then the middle of the list returned.

Your code is complete except for one missing declaration... float().

float(seqq[length / 2 - 1] + seqq[length / 2]) / 2

Like always, D.R.Y. applies. We can still clean up this code some more.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.