Back to Freecodecamp

Step 12

curriculum/challenges/english/blocks/learn-interfaces-by-building-an-equation-solver/6675aaf418b41157f6ccd692.md

latest1.2 KB
Original Source

--description--

It's time to go back to the __init__ method. Depending on the equation type, you'll need to pass a variable number of arguments during the instantiation.

Add a second parameter args to the method and use the * operator to make it accept a variable number of arguments.

--hints--

Your __init__ method should take two parameters, self, and *args.

js
({ test: () => assert(runPython(`_Node(_code).find_class("Equation").find_function("__init__").has_args("self, *args")`)) })

--seed--

--seed-contents--

py
from abc import ABC, abstractmethod


class Equation(ABC):
    degree: int
--fcc-editable-region--
    def __init__(self):
        pass
--fcc-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):
    degree = 1

    def solve(self):
        pass

    def analyze(self):
        pass


lin_eq = LinearEquation()