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
7 Réponses
+ 1
What is your question?
If you need help with your code, please show what you have tried
+ 1
Please link your complete code.
From your code snippet it is unclear what "a" is, what "n" is. Only functions can return.
+ 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)
+ 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
0
sorted(a)
If n % 2 != 0:
return float(a [ int (n/2) ] )
0
def findMedian( a, n):
sorted(a)
If n % 2 != 0:
return float(a [ int (n/2) ] )
0
https://code.sololearn.com/ceSbPZwJuGk1/?ref=app
I tried my best🥲