can any one show me how to write a class for quadratic function in python can any one show me how to write a class for quadratic function in python @Computer Science
What methods and attributes must the class possess?
I'm thinking it must have an a, b, and c attributes. Might be cool to have a solver method.
the methods er x and attributes must be a ,b ,c
if you can also write out a table of x and f values
class QuadraticFunction(object): """ I don't know how to write good docstrings. Sorry! """ def __init__(self, a, b, c): """ I don't know how to write good docstrings. Sorry! """ self.a = a self.b = b self.c = c def solve(): import cmath sol1 = (-self.b + cmath.sqrt(self.b ** 2 - 4 * self.a * self.c)) / 2 sol2 = (-self.b - cmath.sqrt(self.b ** 2 - 4 * self.a * self.c)) / 2 return sol1, sol2 def table(xtable): """ Given a table of x values, returns a list of tuples """ table1 = [] for number in xtable: x = float(number) tuple = x, self.a * (x**2) + self.b * x + self.c table1.append(tuple) return table1
would be cool to have a __repr__ or __str__ method so you can print out the quadratic function.
will try,,,,thanks,,,
Is it alright?
er you there
yes
just wana ask you,,,if you can write out a table of x and f values for x in interval [2, 10]
i mean in quadratic function that i gave to yo
thanks
what quadratic function did you give me?
i mean the class quadratic function,,,,
that's easy. using the code I've written, you would call the table() method with the argument range(2,11), making sure to assign the return value to some name so you create a table with (x, f(x)) tuples, and then you print out all those tuples using a for loop. But if you like to pretty print it, I think the better way would be to write another method.
have to tried the class quadratic function code,,,
er you there
Join our real-time social learning platform and learn together with your friends!