#On the name of ALLAH and may the blessing and peace of Allah #be upon the Messenger of Allah Mohamed Salla Allahu Aliahi Wassalam. #Author : Fouad Teniou #Date : 05/08/08 #Version : 2.4 import cmath as c import math as m ################################################################## # x**2 = -1 an equation which does not have a solution in the real number field # i = Square-Root (-1) < -- > i**2 = -1 made it possible to develop the complex numbers # of the form a + bj ################################################################### class Quadratic: def __call__(self,**args): self.args = args if (len(args) == 3 and self.args.has_key('a') and self.args.get('a') !=0 and self.args.has_key('b') and self.args.has_key('c')): if ((self.args.get('b'))**2-(4*(self.args.get('a'))*(self.args.get('c'))))>=0: self.compute1 = "%2.2f" % float(((self.args.get('b')*(-1))+(m.sqrt((self.args.get('b'))** 2-(4*(self.args.get('a'))*(self.args.get('c'))))))/(2*self.args.get('a'))) self.compute2 = "%2.2f" % float(((self.args.get('b')*(-1))-(m.sqrt((self.args.get('b'))** 2-(4*(self.args.get('a'))*(self.args.get('c'))))))/(2*self.args.get('a'))) elif ((self.args.get('b'))**2-(4*(self.args.get('a'))*(self.args.get('c'))))<0: self.compute1 = "%2.2f" % float(((self.args.get('b')*(-1))+(c.sqrt((self.args.get('b'))** 2-(4*(self.args.get('a'))*(self.args.get('c'))))))/(2*self.args.get('a'))) self.compute2 = "%2.2f" % float(((self.args.get('b')*(-1))-(c.sqrt((self.args.get('b'))** 2-(4*(self.args.get('a'))*(self.args.get('c'))))))/(2*self.args.get('a'))) else: self.args = 0 return (self.compute1,self.compute2) def __str__(self): if self.args == 0: return '\n=0: # self.compute1 = "%2.2f" % float(((self.args.get('b')*(-1))+( m.sqrt((self.args.get('b'))** # 2-(4*(self.args.get('a'))*(self.args.get('c'))))))/(2*self.args.get('a'))) # self.compute2 = "%2.2f" % float(((self.args.get('b')*(-1))-( m.sqrt((self.args.get('b'))** # 2-(4*(self.args.get('a'))*(self.args.get('c'))))))/(2*self.args.get('a'))) # elif ((self.args.get('b'))**2-(4*(self.args.get('a'))*(self.args.get('c'))))<0: # self.compute1 = ((self.args.get('b')*(-1))+( c.sqrt((self.args.get('b')** # 2-(4*(self.args.get('a'))*(self.args.get('c'))))))/(2*self.args.get('a')) # self.compute2 = ((self.args.get('b')*(-1))-(c.sqrt((self.args.get('b'))** # 2-(4*(self.args.get('a'))*(self.args.get('c'))))))/(2*self.args.get('a')) # else: # self.args = 0 # return (self.compute1,self.compute2) # def __str__(self): # if self.args == 0: # return '\n