Nov-05-2019, 02:40 PM
So I'm trying to calculate the median from inputs (int) that a user submits WITHOUT using a statistics module (just want to see how it can be done)
Current function to find the median looks like this
Current function to find the median looks like this
def median(): srt = sorted(lst) mid = len(lst)//2 if len(lst) % 2: return srt[mid] else: med = int((srt[mid] + srt[mid-1])) // 2 return medAnd the whole script looks like this
lst = [] def median(): srt = sorted(lst) mid = len(lst)//2 if len(lst) % 2: return srt[mid] else: med = int((srt[mid] + srt[mid-1])) // 2 return med while True: l = (input("Enter a number ")) if l == "": print(median()) break lst.append(l)