File tree Expand file tree Collapse file tree 8 files changed +50
-32
lines changed Expand file tree Collapse file tree 8 files changed +50
-32
lines changed Original file line number Diff line number Diff line change 44
55@author: Omar Belghaouti
66"""
7- import os
8- from colorama import init , Fore , Style
7+ from cmpx import print_err
98from math import sqrt
10-
11- # Check the os to make output colorful in any platform
12- if os .name == 'nt' :
13- init (convert = True )
14- elif os .name == 'linux' or 'linux2' or 'darwin' :
15- init (convert = False )
169
1710# Complex class for complex number manipulations
1811class Complex ():
@@ -233,10 +226,6 @@ def mod(self):
233226 # Conjugated of a complex number
234227 def con (self ):
235228 return Complex (self .re , - self .im , self .restore )
236- # function to print the error message
237- def print_err (self , err ):
238- print (Fore .RED + '{}: {}' .format (err .__class__ .__name__ , err ))
239- print (Style .RESET_ALL , end = '' )
240229 # Representation function for representing a complex number
241230 def __repr__ (self ):
242231 if (self .re != 0 and self .im > 0 ):
Original file line number Diff line number Diff line change 11from .Complex import Complex
2+ from .error import print_err
23
34__title__ = 'PythonComplex'
45__author__ = 'Omar Belghaouti'
56__maintainer__ = 'Omar Belghaouti'
67__email__ = 'bel_omar18@yahoo.com'
7- __version__ = '0.7.2 '
8+ __version__ = '0.7.5 '
89__license__ = 'MIT'
910__all__ = [
1011 'Complex'
Original file line number Diff line number Diff line change 1+ # -*- coding: utf-8 -*-
2+ from .solve import solve
Original file line number Diff line number Diff line change 1+ # -*- coding: utf-8 -*-
2+ from cmpx import Complex
3+ from cmpx import print_err
4+ from math import sqrt
5+
6+ # Function to solve a second degree (or linear) equation with passing arguments seperatly
7+ def solve (a , b , c = 0 ):
8+ try :
9+ if a and b == 0 :
10+ raise ValueError ('At least give a number to the first two coefficents' )
11+ if c != 0 :
12+ delta = b ** 2 - 4 * a * c
13+ if (delta < 0 ):
14+ solution = (Complex (- b / 2 * a , - sqrt (- delta )/ 2 * a ),
15+ Complex (- b / 2 * a , sqrt (- delta )/ 2 * a ))
16+ elif (delta == 0 ):
17+ solution = (Complex (- b / 2 * a ))
18+ else :
19+ solution = (Complex ((- b - sqrt (delta ))/ 2 * a ),
20+ Complex ((- b + sqrt (delta ))/ 2 * a ))
21+ return solution
22+ else :
23+ return (Complex (- b / a ))
24+ except (ZeroDivisionError , ValueError ) as err :
25+ print_err (err )
Original file line number Diff line number Diff line change 1+ # -*- coding: utf-8 -*-
2+ """
3+ Created on Sun Sep 15 12:04:55 2019
4+
5+ @author: Cds
6+ """
7+ import os
8+ from colorama import init , Fore , Style
9+
10+ # Check the os to make output colorful in any platform
11+ if os .name == 'nt' :
12+ init (convert = True )
13+ elif os .name == 'linux' or 'linux2' or 'darwin' :
14+ init (convert = False )
15+
16+ # function to print the error message
17+ def print_err (err ):
18+ print (Fore .RED + '{}: {}' .format (err .__class__ .__name__ , err ))
19+ print (Style .RESET_ALL , end = '' )
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 55
66setup_args = dict (
77 name = 'cmpx' ,
8- version = '0.7.2 ' ,
8+ version = '0.7.5 ' ,
99 description = 'A package for different operations on complex numbers' ,
1010 long_description_content_type = 'text/markdown' ,
1111 long_description = README ,
You can’t perform that action at this time.
0 commit comments