0
Why answer is 4.5 (I was expecting 5)
https://code.sololearn.com/cs1TEXrLkRWF/?ref=app So It is like this - [4,5,5,4] It took 2 index -5 Then it took 3 index - 5 10/2 = 5 so Output should be 5 instead of 4.5 Please Explain it. Thank You in Advance.
4 Respuestas
+ 2
You sorted the list I guess?
+ 2
Balraj Singh no,your code first took the a first index which is 4, and a second index which is 5 , it added that and divided it by 2.
Which is ofcourse 4.5
the sorted list was [4,4,5,5] . in your code first iteration was skipped,then the second 4 becomes the first index,and 5 becomes the second index
+ 1
That's your list: (4,5,5,4)
Sort it => (4,4,5,5)
Median = (4 + 5) / 2 = 4.5
There is many boilerplate code in your version.
For what is this for-loop?
I was a little bit playing a round in your code. Have a look at this:
https://code.sololearn.com/ch39p12lNcaP/?ref=app
0
if index == 0: print('Frist value') # frist_value