I'm trying to find the median in a list. The equation to find the median is N terms/2. The code i've tried is to find and index the number but when i index i get 0 or an error, why is this?
def Median():
#MedianList_Str = ""
MedianList = [2,4,6]
print("What number do you want to add to the array, enter 0 to exit")
try:
Int = int(input())
if Int == 0:
QuitApp()
else:
MedianList.append(Int)
except:
print("Please enter a number")
MedianT = math.floor(len(MedianList)/2) #finds the nth term
MedianList.sort #sorts the list so you can find the median term
MedianList_Str.join(MedianList)
this is what i've done. I've also tried index
def Median():
MedianList_Str = ""
MedianList = [2,4,6]
print("What number do you want to add to the array, enter 0 to exit")
try:
Int = int(input())
if Int == 0:
QuitApp()
else:
MedianList.append(Int)
except:
print("Please enter a number")
MedianT = math.floor(len(MedianList)/2) #finds the nth term
MedianList.sort #sorts the list so you can find the median term
print(MedianList.index(MedianT))
which gets me 0
what can i do to get me the median? I understand that there already exists such a question but i want to try a different way.