Bird
0
0

Why does this code raise an AttributeError?

medium📝 Debug Q7 of 15
SciPy - Statistical Tests

Why does this code raise an AttributeError?

import scipy.stats as stats

g1 = [3, 4, 5]
g2 = [6, 7, 8]

result = stats.f_oneway(g1, g2)
print(result.statistic())
A<code>statistic</code> is an attribute, not a method; parentheses cause error
BThe groups must be numpy arrays, not lists
CThe function <code>f_oneway</code> returns a tuple, not an object
DThe print statement should be <code>print(result.stat)</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand the result object

    f_oneway returns an object with attributes statistic and pvalue.
  2. Step 2: Identify the error

    Accessing statistic() treats it as a method, but it's an attribute.
  3. Final Answer:

    statistic is an attribute, not a method; parentheses cause error -> Option A
  4. Quick Check:

    Attributes accessed without parentheses [OK]
Quick Trick: Attributes need no parentheses [OK]
Common Mistakes:
MISTAKES
  • Calling attributes as methods
  • Confusing return type of f_oneway
  • Assuming lists are invalid input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes