Learn Interfaces by Building an Equation Solver - Step 11

Tell us what’s happening:

What is wrong in the code? I think the lesson is bugged

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/129.0.0.0 Safari/537.36

Challenge Information:

Learn Interfaces by Building an Equation Solver - Step 11

The step is not bugged.
Do you see the error in the terminal?

Traceback (most recent call last):
  File "main.py", line 25, in <module>
  File "<frozen abc>", line 106, in __new__
  File "main.py", line 14, in __init_subclass__
AttributeError: Cannot create 'LinearEquation' class: missing required attribute 'degree'

The last paragraph of the isntructions say what to do

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.