Bird
0
0

What is the issue with this code?

medium📝 Debug Q6 of 15
SciPy - Statistical Tests
What is the issue with this code?
from scipy.stats import pearsonr
x = [5, 10, 15]
y = [20, 25]
corr, p = pearsonr(x, y)
print(corr)
AThe print statement syntax is incorrect.
BThe pearsonr function is not imported correctly.
CThe input lists have different lengths, causing an error.
DThe variables x and y must be numpy arrays, not lists.
Step-by-Step Solution
Solution:
  1. Step 1: Check input lengths

    pearsonr requires both input arrays to have the same length.
  2. Step 2: Identify error

    Here, x has length 3 and y has length 2, which will raise a ValueError.
  3. Final Answer:

    The input lists have different lengths, causing an error. -> Option C
  4. Quick Check:

    Input arrays must be equal length [OK]
Quick Trick: Input arrays must be same length for pearsonr [OK]
Common Mistakes:
MISTAKES
  • Passing arrays of unequal length
  • Assuming lists must be converted to numpy arrays
  • Misunderstanding import errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes