Skip to content

Commit 9ca1f62

Browse files
committed
Fix bug+Updating __repr__+Updation __version__ to 0..6
The bug was in __iadd__ where it was returning an object without restore argument. Added another condition in __repr__ to return a purely imaginary number to output.
1 parent 584e5ce commit 9ca1f62

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

cmpx/Complex.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def __iadd__(self, other):
158158
other = Complex(other)
159159
self.re += other.re
160160
self.im += other.im
161-
return Complex(self.re, self.im)
161+
return Complex(self.re, self.im, self.restore)
162162
except ValueError as err:
163163
self.print_err(err)
164164
# Operator overloading 13: -=
@@ -236,6 +236,12 @@ def print_err(self, err):
236236
print(Style.RESET_ALL, end='')
237237
# Representation function for representing a complex number
238238
def __repr__(self):
239-
output = str(self.re) + ' + ' + str(self.im) + 'j' if(self.im != 0) else str(self.re)
240-
output = str(self.re) + ' - ' + str(-self.im) + 'j' if (self.im < 0) else output
239+
if(self.re != 0 and self.im > 0):
240+
output = str(self.re) + ' + ' + str(self.im) + 'j'
241+
if(self.re != 0 and self.im < 0):
242+
output = str(self.re) + ' - ' + str(-self.im) + 'j'
243+
if(self.re != 0 and self.im == 0):
244+
output = str(self.re)
245+
if(self.re == 0 and self.im != 0):
246+
output = str(self.im) + 'j'
241247
return output

cmpx/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
__author__ = 'Omar Belghaouti'
55
__maintainer__ = 'Omar Belghaouti'
66
__email__ = 'bel_omar18@yahoo.com'
7-
__version__ = '0.5'
7+
__version__ = '0.6'
88
__license__ = 'MIT'
99
__all__ = [
1010
'Complex'

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.5',
8+
version='0.6',
99
description='Complex class for different operations on complex numbers',
1010
long_description_content_type='text/markdown',
1111
long_description=README,

0 commit comments

Comments
 (0)