Tell us what’s happening:
Task reads “Create an if statement to check if cls does not have a degree attribute.”
The solution shown in the next step is
if not hasattr(cls, "degree"):
I tried other solutions that I believe should work, but they don’t (error message reads “You should create an if statement that checks if cls does not have the attribute degree…”)
My proposed solutions are:
if hasattr(cls, 'degree') == False
if hasattr(cls, 'degree') is False
if hasattr(cls, 'degree') is not True
I understand this project is fairly new, so I just wanted to check if my proposed solutions are correct but simply weren’t taken into consideration when programming the possible answers to the problem, or if they’re just flat-out wrong. Cheers!
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 hasattr(cls, "degree") == False:
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
# 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/127.0.0.0 Safari/537.36
Challenge Information:
Learn Interfaces by Building an Equation Solver - Step 11