i did this question with pythonit was almost donebut i have

i did this question with python,it was almost done,but i have some mistakes in my program,can anyone help me??

this is my program

class LinearEquation:

def __init__(self,a,b,c,d,e,f):
self.__a=a
self.__b=b
self.__c=c
self.__d=d
self.__e=e
self.__f=f

def getA(self):
return self.__a
def getB(self):
return self.__b
def getC(self):
return self.__c
def getD(self):
return self.__d
def getE(self):
return self.__e
def getF(self):
return self.__f
def getisSolvable(self):
deno=(self.__a*self.__d)-(self.__b)*(self.__c)
if deno==0:
return False
else:
return True
def getX(self):
return (self.__e*self.__d-self.__b*self.__f)/(self.__a*self.__d-self.__b*self.__c)
def getY(self):
return (self.__a*self.__f-self.__b*self.__c)/(self.__a*self.__d-self.__b*self.__c)

  
def main():
print(\"Algebra 2 x 2 linear equation\")
print(\"The equations are:\")
print(\"ax+by=e\")
print(\"cx+dy=f\")
print(\"To solve the equations, enter the co-efficient values\")
a,b,c,d,e,f=eval(input(\"Enter value of a,b,c,d,e,f:\"))
linear=LinearEquation(a,b,c,d,e,f,)
if LinearEquation.isSolvable():
print(\"The value of x=\",linear.getX(),\"The value of y=\",linear.getY())
else:
print(\"The equation has no solution\")

main()

and the mistakes are:

Traceback (most recent call last):
File \"C:\\Users\\chen\\Desktop\\Demo7_7.py\", line 47, in <module>
main()
File \"C:\\Users\\chen\\Desktop\\Demo7_7.py\", line 42, in main
if LinearEquation.isSolvable():
AttributeError: type object \'LinearEquation\' has no attribute \'isSolvable\'
>>>

Solution

This error is comming because the class LinearEquation has not function defenition for isSolvable(). Instead it is : getisSolvable().

Please find the corrected code below, with output:

class LinearEquation:
def __init__(self,a,b,c,d,e,f):
self.__a=a
self.__b=b
self.__c=c
self.__d=d
self.__e=e
self.__f=f
def getA(self):
return self.__a
def getB(self):
return self.__b
def getC(self):
return self.__c
def getD(self):
return self.__d
def getE(self):
return self.__e
def getF(self):
return self.__f
def getisSolvable(self):
deno=(self.__a*self.__d)-(self.__b)*(self.__c)
if deno==0:
return False
else:
return True
def getX(self):
return (self.__e*self.__d-self.__b*self.__f)/(self.__a*self.__d-self.__b*self.__c)
def getY(self):
return (self.__a*self.__f-self.__b*self.__c)/(self.__a*self.__d-self.__b*self.__c)
  
def main():
print(\"Algebra 2 x 2 linear equation\")
print(\"The equations are:\")
print(\"ax+by=e\")
print(\"cx+dy=f\")
print(\"To solve the equations, enter the co-efficient values\")
a,b,c,d,e,f=eval(input(\"Enter value of a,b,c,d,e,f:\"))
linear=LinearEquation(a,b,c,d,e,f,)
if LinearEquation.getisSolvable(linear):
print(\"The value of x=\",linear.getX(),\"The value of y=\",linear.getY())
else:
print(\"The equation has no solution\")
main()

---------------------------------------------------------------

OUTPUT:

i did this question with python,it was almost done,but i have some mistakes in my program,can anyone help me?? this is my program class LinearEquation: def __in
i did this question with python,it was almost done,but i have some mistakes in my program,can anyone help me?? this is my program class LinearEquation: def __in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site