0

Given N elements of integer array and we have to find its median. A median is the value present at the centre of a sorted array

15th May 2022, 12:22 PM
Anahit Yeghyan
7 Respuestas
+ 1
What is your question? If you need help with your code, please show what you have tried
15th May 2022, 12:23 PM
Lisa
Lisa - avatar
+ 1
Please link your complete code. From your code snippet it is unclear what "a" is, what "n" is. Only functions can return.
15th May 2022, 12:30 PM
Lisa
Lisa - avatar
+ 1
You can link your code like this: Go to Code section, click +, select the programming language, insert your code, save. Come back to this thread, click +, Insert Code, sort for My Code Bits, select your code. * There is no need to cast the result to a float * watch the indentation * watch the spelling * you don't need to pass n as it will be the length of a * sorted() does not operate in-place – "a" will not be sorted which you can see if you print it * consider the case when n is an even number (edited)
15th May 2022, 12:37 PM
Lisa
Lisa - avatar
+ 1
Consider revising some Python basics before you do this task: https://www.sololearn.com/Course/Python-for-Beginners/?ref=app Then re-read my suggestions
15th May 2022, 12:52 PM
Lisa
Lisa - avatar
0
sorted(a) If n % 2 != 0: return float(a [ int (n/2) ] )
15th May 2022, 12:27 PM
Anahit Yeghyan
0
def findMedian( a, n): sorted(a) If n % 2 != 0: return float(a [ int (n/2) ] )
15th May 2022, 12:33 PM
Anahit Yeghyan
15th May 2022, 12:42 PM
Anahit Yeghyan