Covariance of Study Hours and Scores
Lantern Tutors runs after-school maths sessions and has just finished a pilot. For each student they logged two things: hours spent on the practice app that week, and the mark out of 10 on Friday's quiz. The two lists line up by position - the first hours figure and the first mark belong to the same student, and so on down the class.
The owner's first question is the crude one: when a student's hours are above the group average, is that student's mark usually above the group average too? She wants the raw co-movement figure - the one still carrying its hour-times-mark units - before anyone tidies it into something unitless. She runs the same line over each cohort, and the cohorts are not the same size.
Task: Print the sample covariance between the hours and the marks - the unbiased version, treating each cohort as a sample drawn from a larger intake rather than as the entire population - rounded to 2 decimals.
Input
Two lines. The first holds the hours, one per student, separated by single spaces. The second holds the marks in the same order. Both lines hold the same number of entries, and there are at least two.
Output
One line holding the sample covariance, rounded to 2 decimals and printed the way Python prints a float - 1.5, and -8.67 when the two move in opposite directions.
Example:
Input:
1 2 3 4 5
2 4 5 4 5
Output:
1.5
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in