We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Enter your code here. Read input from STDIN. Print output to STDOUT
I have submitted this code still getting compilation error
physics_marks = [15,12,8,8,7,7,7,6,5,3]
history_score = [10,25,17,11,13,17,20,13,9,15]
calculate correlation coefficient
x_avg = sum(physics_marks)/10
y_avg = sum(history_score)/10
corr_coeff_num = sum([(physics_marks[i] - x_avg)*(history_score[i]-y_avg) for i in range(10)])
corr_coeff_deno = (sum([(physics_marks[i]**2)for i in range(10)])*sum([(history_score[i]**2)for i in range(10)]))**0.5
correlation_coefficient = corr_coeff_num/corr_coeff_deno
print(f"{correlation_coefficient:.3f}")
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Correlation and Regression Lines - A Quick Recap #1
You are viewing a single comment's thread. Return to all comments →
Enter your code here. Read input from STDIN. Print output to STDOUT
I have submitted this code still getting compilation error physics_marks = [15,12,8,8,7,7,7,6,5,3] history_score = [10,25,17,11,13,17,20,13,9,15]
calculate correlation coefficient
x_avg = sum(physics_marks)/10 y_avg = sum(history_score)/10 corr_coeff_num = sum([(physics_marks[i] - x_avg)*(history_score[i]-y_avg) for i in range(10)]) corr_coeff_deno = (sum([(physics_marks[i]**2)for i in range(10)])*sum([(history_score[i]**2)for i in range(10)]))**0.5 correlation_coefficient = corr_coeff_num/corr_coeff_deno print(f"{correlation_coefficient:.3f}")