From 0e0568fcec287bbcf675ad95b2a488b43f89c9b0 Mon Sep 17 00:00:00 2001 From: FatimaSaeed123 <68647842+FatimaSaeed123@users.noreply.github.com> Date: Sun, 18 Sep 2022 17:25:45 +0500 Subject: [PATCH] Create q3_sol.py --- q3_sol.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 q3_sol.py diff --git a/q3_sol.py b/q3_sol.py new file mode 100644 index 0000000..7fbf134 --- /dev/null +++ b/q3_sol.py @@ -0,0 +1,25 @@ +def Median(arr): + n = len(arr) + # If length of array is even + if n % 2 == 0: + x = n // 2 + y = arr[x] + z = arr[x - 1] + result = (y + z) / 2 + return result + + # If length of array is odd + else: + x = n // 2 + result = arr[x] + return result + + +if __name__ == "__main__": + arr1 = [ 1,2,3 ] + arr2 = [ 4,5 ] + # Concatenating arrays + arr3 = arr1 + arr2 + # Sorting the resultant array + arr3.sort() + print("Median of arrays is = ", Median(arr3))