Learn Interfaces by Building an Equation Solver - Step 14

Tell us what’s happening:

May I ask, what is wrong with my code here? I’ve spent a couple hours on this one problem, looked stuff up, phoned a friend and no luck. It just looks like it doesn’t like my string in the raised error, but I copied and pasted that. Can’t wrap my head around this.

Your code so far

from abc import ABC, abstractmethod

# User Editable Region

class Equation(ABC):
    degree: int
    
    def __init__(self, *args):
        if (self.degree + 1) != len(args):
            raise TypeError(
                f"'{self.__class__.__name__}' object takes {self.degree + 1} positional arguments but {len(args)} were given"
            )
        for arg in args:
            if not isinstance(arg, (int, float)):
                raise TypeError(f"Coefficients must be of type 'int' or 'float'")

# 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):
    degree = 1
    
    def solve(self):
        pass
    
    def analyze(self):
        pass
    
lin_eq = LinearEquation(2, 3)

print(lin_eq)
args = [1,2,3,False]
for arg in args:
    if not isinstance(arg, (int, float)):
        raise TypeError(f"Coefficients must be of type 'int' or 'float'")
print(type(args[3]))
print(f'The type {type(args[3])} of the 4th index of args ({args[3]}) is a Boolean: "{type(args[3]) == bool}"')
print(f"Is the 4th index ({args[3]}) of args ({args[3]}) an instance of 'int' or 'float'? '{isinstance(args[3], (int, float))}'")
print(f'Is "False" an integer? "{isinstance(False, int)}"')

Your browser information:

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

Challenge Information:

Learn Interfaces by Building an Equation Solver - Step 14

Welcome to the forum @theobigdog

From about line forty onwards, you have extra code - please remove it.
Also, in TypeError remove the f before the first quote mark.

Happy coding

Thank you so much for the welcome and the help! All the nonsense at the end was my troubleshooting. The code still worked fine and passed, even with all of it included, as long as I got rid of the f-string. So, I’m curious why that was preventing me from progressing. It still will give the same result either way. Any ideas?

I’m also curious about the fact that sending a boolean to the function still worked. Is that because it’s just stored as a 0? Seems like there is potential for issues there, but I don’t really know.