Bird
0
0

Find the bug in this code:

medium📝 Debug Q7 of 15
SciPy - Statistical Tests
Find the bug in this code:
from scipy.stats import spearmanr
x = [1, 2, 3, 4]
y = [4, 3, 2, 1]
result = spearmanr(x)
print(result.correlation)
Ax and y must be numpy arrays
Bspearmanr does not return an object with correlation attribute
Cprint statement missing parentheses
DMissing second argument y in spearmanr call
Step-by-Step Solution
Solution:
  1. Step 1: Check function call parameters

    spearmanr requires two inputs to compute correlation between them. Here only x is passed.
  2. Step 2: Identify error

    Missing y argument causes TypeError for missing required positional argument.
  3. Final Answer:

    Missing second argument y in spearmanr call -> Option D
  4. Quick Check:

    spearmanr(x, y) needs both inputs [OK]
Quick Trick: Always pass both variables to spearmanr [OK]
Common Mistakes:
MISTAKES
  • Passing only one argument
  • Assuming default second argument
  • Confusing function signature

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes