Question: I'm trying to find the median using the python code set out for me with the functions but I can't seem to hack it. any
I'm trying to find the median using the python code set out for me with the functions but I can't seem to hack it. any help please?
# Quarterly change from a year earlier in visits to the UK from overseas residents (ONS)
visits = [6.9,1.6,2,7.4,8.8,1.5,3.6,13.1,7.9,8.6,9.2,-5.8,-3.4,-4.5,-3,3.8,-2.5,-1.5,2.8,6.4,-16.1]
def median(visits): number_of_values = len(visits) sorted_list = sorted(visits) # 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(visits)[quotient] else: result = (sorted(visits)[quotient - 1] + sorted(visits)[quotient]) / 2 print(result)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
