Back to Freecodecamp

Step 8

curriculum/challenges/english/blocks/learn-interfaces-by-building-an-equation-solver/662f6d7c92381a3049e4c987.md

latest1.1 KB
Original Source

--description--

An interface doesn't have to define only abstract methods, but it can also implement methods to be inherited by the concrete classes.

Before taking care of the actual implementation of solve and analyze, within the Equation class, define an __init__ method. Do not use any decorator on it.

--hints--

You should define an __init__ method in your Equation class.

js
({ test: () => assert(runPython(`_Node(_code).find_class("Equation").has_function("__init__")`)) })

Your __init__ method should take one parameter, self.

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

--seed--

--seed-contents--

py
--fcc-editable-region--
from abc import ABC, abstractmethod


class Equation(ABC):
    @abstractmethod
    def solve(self):
        pass
        
    @abstractmethod
    def analyze(self):
        pass


class LinearEquation(Equation):
    def solve(self):
        pass

    def analyze(self):
        pass


lin_eq = LinearEquation()
--fcc-editable-region--