-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay 1 Interquartile Range.py
More file actions
48 lines (35 loc) · 968 Bytes
/
Day 1 Interquartile Range.py
File metadata and controls
48 lines (35 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/python3
import math
import os
import random
import re
import sys
import statistics
#
# Complete the 'interQuartile' function below.
#
# The function accepts following parameters:
# 1. INTEGER_ARRAY values
# 2. INTEGER_ARRAY freqs
#
def interQuartile(values, freqs):
# Print your answer to 1 decimal place within this function
s = []
n = len(values)
for i in range(n):
s += [values[i]] * freqs[i]
sumFreq = sum(freqs)
mid = sumFreq // 2
s.sort()
if n % 2 != 0:
q1 = statistics.median(s[:mid])
q3 = statistics.median(s[mid + 1:])
else:
q1 = statistics.median(s[:mid])
q3 = statistics.median(s[mid:])
print("{:.1f}".format(q3 - q1))
if __name__ == '__main__':
n = int(input().strip())
val = list(map(int, input().rstrip().split()))
freq = list(map(int, input().rstrip().split()))
interQuartile(val, freq)