Dec-11-2018, 11:28 PM
Can anyone assist with this, I am trying to import a calculation from maths.py into my file main.py, I think i have it set properly to pull the calculation through by using
I need to find the median of a list of numbers and have it print out the median.
this is my code for the calculating the median
any help and advice would be great - I'm using 3.7.0 if that helps at all.
from maths import medianto get the median function to come over to main.py
I need to find the median of a list of numbers and have it print out the median.
this is my code for the calculating the median
def median(alist): """ Calculates the median of a list of numbers.The list must not be empty.""" number_of_values = len(alist) sorted_list = sorted(alist) # Two cases, depending on whether the number of values is odd or even. quotient = number_of_values // 2 remainder = number_of_values % 2 if (remainder == 1): result = sorted_list[quotient] else: result = (sorted_list[quotient - 1] + sorted_list[quotient]) / 2 return resulthow can i make this run so that it will give me the median in main.py?
any help and advice would be great - I'm using 3.7.0 if that helps at all.