Skip to content

Commit 95a8125

Browse files
committed
Change delta to solve+Change solve to equations
1 parent 43fe8a3 commit 95a8125

File tree

8 files changed

+50
-32
lines changed

8 files changed

+50
-32
lines changed

cmpx/Complex.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,8 @@
44
55
@author: Omar Belghaouti
66
"""
7-
import os
8-
from colorama import init, Fore, Style
7+
from cmpx import print_err
98
from 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
1811
class 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):

cmpx/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from .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'

cmpx/equations/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# -*- coding: utf-8 -*-
2+
from .solve import solve

cmpx/equations/solve.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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)

cmpx/error.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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='')

cmpx/solve/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

cmpx/solve/delta.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup_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,

0 commit comments

Comments
 (0)