Learn Interfaces by Building an Equation Solver - Step 11

Tell us what’s happening:

I don’t know what’s wrong
there’s an error that says:
def init_subclass(cls):
if not hasattr(cls, “degree”):
raise AttributeError(
f"Cannot create ‘{cls.name}’ class: missing required attribute ‘degree’"
)

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):
        if not hasattr(cls, "degree"):
            raise AttributeError(
                f"Cannot create '{cls.__name__}' class: missing required attribute 'degree'"
            )
            
    @abstractmethod
    def solve(self):
        pass
        
    @abstractmethod
    def analyze(self):
        pass


class LinearEquation(Equation):
    

# User Editable Region

    def solve(self):
        pass

    def analyze(self):
        pass


lin_eq = LinearEquation()

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0

Challenge Information:

Learn Interfaces by Building an Equation Solver - Step 11

fix the error that has appeared in the terminal by declaring a degree class attribute inside the LinearEquation class. This attribute should represent the degree of the equation, which is the exponent of the highest x term. Therefore, assign the integer 1 to the degree atttribute.

Did you read this part?

1 Like