Sort by

recency

|

129 Discussions

|

  • + 0 comments

    The problem statement is misleading. You are told that you are required to take the input from stdin (python3 -> input())

    The sample also has strings at the begginng that need to be handled on input.

    However the actual submission is passed by hardcoding the example data as numerical lists in the code which is not what the instructions state. There is no feedback on the submission either to see if stdin/inputs are even being provided in the submission test cases.

  • + 0 comments

    physics = [15, 12, 8, 8, 7, 7, 7, 6, 5, 3]

    history = [10, 25, 17, 11, 13, 17, 20, 13, 9, 15]

    Step 1: Calculate means of both lists

    mean_x = sum(physics) / len(physics)

    mean_y = sum(history) / len(history)

    Step 2: Calculate numerator (Covariance)

    sum_xy = sum((x - mean_x) * (y - mean_y) for x, y in zip(physics, history))

    Step 3: Calculate the denominator (Standard deviations of x and y)

    sum_x_sq = sum((x - mean_x) ** 2 for x in physics)

    sum_y_sq = sum((y - mean_y) ** 2 for y in history)

    Step 4: Pearson correlation coefficient formula

    r = sum_xy / ( (sum_x_sq ** 0.5) * (sum_y_sq ** 0.5) )

    Step 5: Print the result

    print(round(r, 3)) # Rounding to 3 decimal places

  • + 0 comments

    physics = [15, 12, 8, 8, 7, 7, 7, 6, 5, 3] history = [10, 25, 17, 11, 13, 17, 20, 13, 9, 15]

    Step 1: Calculate means of both lists

    mean_x = sum(physics) / len(physics) mean_y = sum(history) / len(history)

    Step 2: Calculate numerator (Covariance)

    sum_xy = sum((x - mean_x) * (y - mean_y) for x, y in zip(physics, history))

    Step 3: Calculate the denominator (Standard deviations of x and y)

    sum_x_sq = sum((x - mean_x) ** 2 for x in physics) sum_y_sq = sum((y - mean_y) ** 2 for y in history)

    Step 4: Pearson correlation coefficient formula

    r = sum_xy / ( (sum_x_sq ** 0.5) * (sum_y_sq ** 0.5) )

    Step 5: Print the result

    print(round(r, 3)) # Rounding to 3 decimal places

  • + 0 comments

    Thank you for sharing this quick recap. I was looking for this for my fumot vape project.

  • + 0 comments
    physics = [15, 12, 8, 8, 7, 7, 7, 6, 5, 3]
    history = [10, 25, 17, 11, 13, 17, 20, 13, 9, 15]
    
    n = len(physics)
    
    mean_x = sum(physics) / n
    mean_y = sum(history) / n
    
    sum_xy = sum((physics[i] - mean_x) * (history[i] - mean_y) for i in range(n))
    sum_xx = sum((physics[i] - mean_x)**2 for i in range(n))
    sum_yy = sum((history[i] - mean_y)**2 for i in range(n))
    
    r = sum_xy / (sum_xx*sum_yy)**(1/2)
    
    print(f"{r:.3f}")