@@ -44,7 +44,10 @@ def __add__(self, other):
4444 if other is None :
4545 raise ValueError ('The second number is None' )
4646 if not isinstance (other , Complex ):
47- other = Complex (other )
47+ if isinstance (other , complex ):
48+ other = Complex (other .real , other .imag )
49+ else :
50+ other = Complex (other )
4851 return Complex (self .re + other .re , self .im + other .im , self .restore )
4952 except ValueError as err :
5053 print_err (err )
@@ -54,7 +57,10 @@ def __sub__(self, other):
5457 if other is None :
5558 raise ValueError ('The second number is None' )
5659 if not isinstance (other , Complex ):
57- other = Complex (other )
60+ if isinstance (other , complex ):
61+ other = Complex (other .real , other .imag )
62+ else :
63+ other = Complex (other )
5864 return Complex (self .re - other .re , self .im - other .im , self .restore )
5965 except ValueError as err :
6066 print_err (err )
@@ -64,7 +70,10 @@ def __mul__(self, other):
6470 if other is None :
6571 raise ValueError ('The second number is None' )
6672 if not isinstance (other , Complex ):
67- other = Complex (other )
73+ if isinstance (other , complex ):
74+ other = Complex (other .real , other .imag )
75+ else :
76+ other = Complex (other )
6877 return Complex (self .re * other .re - self .im * other .im , self .re * other .im + self .im * other .re , self .restore )
6978 except ValueError as err :
7079 print_err (err )
@@ -74,7 +83,10 @@ def __truediv__(self, other):
7483 if other is None :
7584 raise ValueError ('The second number is None' )
7685 if not isinstance (other , Complex ):
77- other = Complex (other )
86+ if isinstance (other , complex ):
87+ other = Complex (other .real , other .imag )
88+ else :
89+ other = Complex (other )
7890 den = other * other .con ()
7991 num = self * other .con ()
8092 if den .re == 0 and self .restore :
@@ -89,7 +101,10 @@ def __floordiv__(self, other):
89101 if other is None :
90102 raise ValueError ('The second number is None' )
91103 if not isinstance (other , Complex ):
92- other = Complex (other )
104+ if isinstance (other , complex ):
105+ other = Complex (other .real , other .imag )
106+ else :
107+ other = Complex (other )
93108 den = other * other .con ()
94109 num = self * other .con ()
95110 if den .re == 0 and self .restore :
@@ -103,7 +118,10 @@ def __gt__(self, other):
103118 if other is None :
104119 raise ValueError ('The second number is None' )
105120 if not isinstance (other , Complex ):
106- other = Complex (other )
121+ if isinstance (other , complex ):
122+ other = Complex (other .real , other .imag )
123+ else :
124+ other = Complex (other )
107125 return self .mod () > other .mod ()
108126 except ValueError as err :
109127 print_err (err )
@@ -113,7 +131,10 @@ def __ge__(self, other):
113131 if other is None :
114132 raise ValueError ('The second number is None' )
115133 if not isinstance (other , Complex ):
116- other = Complex (other )
134+ if isinstance (other , complex ):
135+ other = Complex (other .real , other .imag )
136+ else :
137+ other = Complex (other )
117138 return self .mod () >= other .mod ()
118139 except ValueError as err :
119140 print_err (err )
@@ -123,7 +144,10 @@ def __lt__(self, other):
123144 if other is None :
124145 raise ValueError ('The second number is None' )
125146 if not isinstance (other , Complex ):
126- other = Complex (other )
147+ if isinstance (other , complex ):
148+ other = Complex (other .real , other .imag )
149+ else :
150+ other = Complex (other )
127151 return not self >= other
128152 except ValueError as err :
129153 print_err (err )
@@ -133,7 +157,10 @@ def __le__(self, other):
133157 if other is None :
134158 raise ValueError ('The second number is None' )
135159 if not isinstance (other , Complex ):
136- other = Complex (other )
160+ if isinstance (other , complex ):
161+ other = Complex (other .real , other .imag )
162+ else :
163+ other = Complex (other )
137164 return not self > other
138165 except ValueError as err :
139166 print_err (err )
@@ -143,7 +170,10 @@ def __eq__(self, other):
143170 if other is None :
144171 raise ValueError ('The second number is None' )
145172 if not isinstance (other , Complex ):
146- other = Complex (other )
173+ if isinstance (other , complex ):
174+ other = Complex (other .real , other .imag )
175+ else :
176+ other = Complex (other )
147177 return (self .re == other .re ) and (self .im == other .im )
148178 except ValueError as err :
149179 print_err (err )
@@ -153,7 +183,10 @@ def __ne__(self, other):
153183 if other is None :
154184 raise ValueError ('The second number is None' )
155185 if not isinstance (other , Complex ):
156- other = Complex (other )
186+ if isinstance (other , complex ):
187+ other = Complex (other .real , other .imag )
188+ else :
189+ other = Complex (other )
157190 return not self == other
158191 except ValueError as err :
159192 print_err (err )
@@ -163,7 +196,10 @@ def __iadd__(self, other):
163196 if other is None :
164197 raise ValueError ('The second number is None' )
165198 if not isinstance (other , Complex ):
166- other = Complex (other )
199+ if isinstance (other , complex ):
200+ other = Complex (other .real , other .imag )
201+ else :
202+ other = Complex (other )
167203 self .re += other .re
168204 self .im += other .im
169205 return Complex (self .re , self .im , self .restore )
@@ -175,7 +211,10 @@ def __isub__(self, other):
175211 if other is None :
176212 raise ValueError ('The second number is None' )
177213 if not isinstance (other , Complex ):
178- other = Complex (other )
214+ if isinstance (other , complex ):
215+ other = Complex (other .real , other .imag )
216+ else :
217+ other = Complex (other )
179218 self .re -= other .re
180219 self .im -= other .im
181220 return Complex (self .re , self .im , self .restore )
@@ -187,7 +226,10 @@ def __imul__(self, other):
187226 if other is None :
188227 raise ValueError ('The second number is None' )
189228 if not isinstance (other , Complex ):
190- other = Complex (other )
229+ if isinstance (other , complex ):
230+ other = Complex (other .real , other .imag )
231+ else :
232+ other = Complex (other )
191233 self .re = self .re * other .re - self .im * other .im
192234 self .im = self .re * other .im + self .im * other .re
193235 return Complex (self .re , self .im , self .restore )
@@ -199,7 +241,10 @@ def __idiv__(self, other):
199241 if other is None :
200242 raise ValueError ('The second number is None' )
201243 if not isinstance (other , Complex ):
202- other = Complex (other )
244+ if isinstance (other , complex ):
245+ other = Complex (other .real , other .imag )
246+ else :
247+ other = Complex (other )
203248 den = other * other .con ()
204249 num = self * other .con ()
205250 if den .re == 0 and self .restore :
@@ -216,7 +261,10 @@ def __ifloordiv__(self, other):
216261 if other is None :
217262 raise ValueError ('The second number is None' )
218263 if not isinstance (other , Complex ):
219- other = Complex (other )
264+ if isinstance (other , complex ):
265+ other = Complex (other .real , other .imag )
266+ else :
267+ other = Complex (other )
220268 den = other * other .con ()
221269 num = self * other .con ()
222270 if den .re == 0 and self .restore :
0 commit comments