Learn Interfaces by Building an Equation Solver - Step 11

Tell us what’s happening:

i’m so confused the nameerror im getting makes no sense i haven’t called on a variable that isnt there

Your code so far

from abc import ABC, abstractmethod


class Equation(ABC):
    degree: int
    
    def __init__(self):
        pass

# User Editable Region

    def __init_subclass__(cls):
        pass

    @abstractmethod
    def solve(self,):
        pass
        
    @abstractmethod
    def analyze(self):
        pass
    if not hasattr(cls,'degree'):
        raise AttributeError(f"Cannot create '{cls.__name__}' class: missing required attribute 'degree'")

        


class LinearEquation(Equation):
    degree: int = 1
    

# User Editable Region

    def solve(self):
        pass

    def analyze(self):
        pass


lin_eq = LinearEquation()

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

Learn Interfaces by Building an Equation Solver - Step 11

The if statement placed inside of __init_subclass__ as that has the cls variable. As long as there is something else you can place inside a method, you don’t need the pass statements either.

1 Like

no i think you are wrong you do need the pass statments for solve and analyze i just passed the step there and i kept them but thanks for the advice, the first point you made helped me