Learn Interfaces by Building an Equation Solver - Step 14

Tell us what’s happening:

whats wrong with this? im confused on the part where it says tuple, also i’d like to mention that alot of the recent steps and projects, the wording on them is horrible, they need to fix it and more people will address this issue when more people do these projects.

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 args() != isinstance(int):
raise TypeError("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)

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

Learn Interfaces by Building an Equation Solver - Step 14

do i need the if statement??? this is what i’m saying about how badly worded this thing is sometimes it tells you to check something and it means an if statement other times it doesn’t mean an if statement

also forget the brackets i’ve removed that an ive made it doesnt = int still confused what to do with isintance and the tuple part

my updated code

for item in args:
if arg != isinstance(args,(int,float)):
raise TypeError("Coefficients must be of type 'int' or 'float'")

First, you need to get the correct syntax of the for loop and use the correct variables. This is a very basic thing in Python and if you don’t understand it you won’t be able to continue.

Make sure you understand how a for loop works. You can review for loops here:
https://www.w3schools.com/python/python_for_loops.asp

https://www.geeksforgeeks.org/python-for-loops/

Please show a basic for loop that iterates through args and prints each item.

yeah i don’t know why i got the args mixed up also the code here it a bit old i meant to put for arg in args ill change it that’s my fault
but im still getting typeError

updated to my actual code:

for arg in args:
if arg != isinstance(args,(int,float)):
raise TypeError("Coefficients must be of type 'int' or 'float'")

i fixed my dumb mistake after 1 hour, so bascially i was trying to compare arg with the isinstance but thats not what it asked me it asked me to checks if the argument at the current iteration is not an instance of int or float so there was no need for the == to or even the !=

Slow down, make sure you understand each function that you’re using, or else you cheat yourself out of learning.

You can learn about isinstance() and what it returns here:
https://www.w3schools.com/python/ref_func_isinstance.asp

I would suggest testing out things in a separate Google Colab editor so you can print out results and see what they do.

If you had printed like this

print(isinstance(args,(int,float))
print(arg)

You would see that comparing these would never work. You would also quickly learn that your other for loops were using the wrong variable.

By not testing things and printing out your statements and variables you are flying blind. You need to open your eyes and see what the code is doing. print() everything, always