You are viewing a single comment's thread. Return to all comments →
def quartiles(n,arr): arr=sorted(arr) if n%2==1: q2=arr[n//2] q1=statistics.median(arr[:n//2]) q3=statistics.median(arr[n//2+1:]) else: q2=(arr[n//2]+arr[n//2-1])/2 q1=statistics.median(arr[:n//2]) q3=statistics.median(arr[n//2:]) return [int(q1),int(q2),int(q3)]
or
def find_median(arr): n = len(arr) if n % 2 == 1: return arr[n // 2] else: return (arr[n // 2] + arr[n // 2 - 1]) / 2 def quartiles(n, arr): arr = sorted(arr) q2 = find_median(arr) if n % 2 == 1: lower_half = arr[:n // 2] upper_half = arr[n // 2 + 1:] else: lower_half = arr[:n // 2] upper_half = arr[n // 2:] q1 = find_median(lower_half) q3 = find_median(upper_half) return [int(q1), int(q2), int(q3)]
undefined `
Seems like cookies are disabled on this browser, please enable them to open this website
Day 1: Quartiles
You are viewing a single comment's thread. Return to all comments →
or
undefined `