# Practice makes perfect: 15/15- Median

#1

No sure whats wrong with my code here, when I read through it it seems ok but the output at the end is apparently wrong, any suggestions?

``````def median(want_this_median):
want_this_median = sorted(want_this_median)
if len(want_this_median) % 2 == 0:
first_ref = len(want_this_median)/ 2
second_ref = len(want_this_median)/2 -1
total = want_this_median[first_ref] + want_this_median[second_ref] / 2.0
else:
list_no = (len(want_this_median)/2)
return want_this_median[list_no]``````

#2

on this line

``total = want_this_median[first_ref] + want_this_median[second_ref] / 2.0``

you might wanna do

``(total = want_this_median[first_ref] + want_this_median[second_ref] )/ 2.0``

to make it work .think BEDMAS

Also push that line one space back

something like this

``````def median(want_this_median):
want_this_median = sorted(want_this_median)
if len(want_this_median) % 2 == 0:
first_ref = int(len(want_this_median)/ 2  )
second_ref = int(len(want_this_median)/2 - 1)
total = (want_this_median[first_ref] + want_this_median[second_ref])/ 2.0
else:
list_no = len(want_this_median)/2
return want_this_median[list_no]

print (median([4,5,5,4]))``````

#3

thanks, I only realised that like 10 minutes after posting this, totally forgot about the whole "these are just numbers" part of it

#4

hii i think that it is a way for solve this task

def media(lista):
lista.sort()
if len(lista)%2.0==0:
a=lista[(len(lista)/2)]
b=lista[(len(lista)/2)-1]
c=((a+b)/2.0)
return c
else:
a=lista[(len(lista)/2)]
return a
media([1,34,6,8,0])

#5