Sort 86 Discussions, By:
Please Login in order to post a comment
If the numpy and scipy cannot be used, the parctice is pretty useless for a python programmer. You don't write code to calculate everything unless you really have to or you want to know the mathematics behind.
This is a really badly designed Hackerrank evaluation on an interesting question.
1) You can get full points for just printing out the hardcoded text answer 0.145 ಠ_ಠ
2) The question says to read from stdin but then the "submit" button doesn't come with any stdin test cases, so you need to hardcode the input as a list into your solution.
There are plenty of ways to make this an interesting problem - what if you need to read in from a file? What if the input can be any arbitrary number of lists?
The calculation itself is a worthwhile exercise - I suggest doing it manually (without using numpy), independent of how silly this HR evaluation is.
I have changed my code,got it right
Score1 = [15,12,8,8,7,7,7,6,5,3]
Score2 = [10,25,17,11,13,17,20,13,9,15]
m1 = (sum(Score1)/len(Score1))
m2 = (sum(Score2)/len(Score1))
Score_1 = [x-m1 for x in Score1]
Score_2 = [x-m2 for x in Score2]
n1 = sum([x*y for x,y in zip(Score_1,Score_2)])
Score1 = sum([(x-m1)**2 for x in Score1])
Score2 = sum([(x-m2)**2 for x in Score2])
n2 = (Score1**(1/2))*(Score2**(1/2))
r = n1/n2
What is the input data for test case #0 ? My code is working, but it keeps saying runtime error.
For users of R, a tip is to use cat() instead of print() for output. Formatting works a little bit differently with cat() and print()