mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
...
This commit is contained in:
parent
9d9ec9a6d0
commit
c79cd6dca6
@ -17,7 +17,12 @@ class complex:
|
|||||||
return complex(self.real, -self.imag)
|
return complex(self.real, -self.imag)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"({self.real}+{self.imag}j)"
|
s = ['(', str(self.real)]
|
||||||
|
if self.imag >= 0:
|
||||||
|
s.append('+')
|
||||||
|
s.append(str(self.imag))
|
||||||
|
s.append('j)')
|
||||||
|
return ''.join(s)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if type(other) is complex:
|
if type(other) is complex:
|
||||||
|
@ -20,3 +20,8 @@ res = sqrt(1+2j)
|
|||||||
assert isclose(res, 1.272019649514069+0.7861513777574233j)
|
assert isclose(res, 1.272019649514069+0.7861513777574233j)
|
||||||
|
|
||||||
assert {1+2j: 1}[1+2j] == 1
|
assert {1+2j: 1}[1+2j] == 1
|
||||||
|
|
||||||
|
assert repr(1+2j) == '(1.0+2.0j)'
|
||||||
|
assert repr(1+0j) == '(1.0+0.0j)'
|
||||||
|
assert repr(-1-3j) == '(-1.0-3.0j)'
|
||||||
|
assert repr(1-3j) == '(1.0-3.0j)'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user