Advertisement
trds

classLinearEquation

Jan 30th, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. class LinearEquation:
  2.     def __init__(self, a,b,c,d,e,f):
  3.         self.__a = a
  4.         self.__b = b
  5.         self.__c = c
  6.         self.__d = d
  7.         self.__e = e
  8.         self.__f = f
  9.  
  10.     def getA(self):
  11.         return self.__a
  12.     def getB(self):
  13.         return self.__b
  14.     def getC(self):
  15.         return self.__c
  16.     def getD(self):
  17.         return self.__d
  18.     def getE(self):
  19.         return self.__e
  20.     def getF(self):
  21.         return self.__f
  22.  
  23. # isSolvable()<=>ab-bc!=0
  24.  
  25.     def isSolvable(self):
  26.         if ((self.__a * self.__d - self.__b * self.__c)!=0):
  27.             return True
  28.         else:
  29.             return False
  30.  
  31.     def getX(self):
  32.         return ((self.__e * self.__d - self.__b * self.__f)/(self.__a * self.__d - self.__b * self.__c))
  33.     def getY(self):
  34.         return ((self.__a * self.__f - self.__e * self.__c)/(self.__a * self.__d - self.__b * self.__c))
  35.  
  36.     def __repr__(self):
  37.         s1= ("{}x + {} + {}y = {}" .format(self.__a, self.__b, self.__e))
  38.         s2= ("{}x + {} + {}y= {}". format(self.__c, self.__d, self.__f))
  39.         rezultat=s1+"\n"+s2
  40.         return rezultat
  41.  
  42. s1 = LinearEquation (2,3,1,7,5,8)
  43. if s1.isSolvable():
  44.     x=s1.getX()
  45.     y=s1.getY()
  46.     print ("Sistemul are solutia ({},{})".format(x,y))
  47.  
  48. else:
  49.     print ("Sistemul nu are solutie")
  50.  
  51. s2 = LinearEquation (2,3,2,3,4,1)
  52. if s2.isSolvable():
  53.     x=s2.getX()
  54.     y=s2.getY()
  55.     print ("Sistemul are solutia ({},{})".format(x,y))
  56. else:
  57.     print ("Sistemul nu are solutie")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement