ch01-12: clean up by @eumiro

This commit is contained in:
Luciano Ramalho
2021-02-14 20:28:07 -03:00
parent 584a7f21ca
commit 03ace4f4ae
33 changed files with 1383 additions and 86 deletions

View File

@@ -0,0 +1,12 @@
>>> from vector2d import Vector
>>> v1 = Vector(2, 4)
>>> v2 = Vector(2, 1)
>>> v1 + v2
Vector(4, 5)
>>> v = Vector(3, 4)
>>> abs(v)
5.0
>>> v * 3
Vector(9, 12)
>>> abs(v * 3)
15.0

View File

@@ -29,7 +29,7 @@ Scalar multiplication::
"""
from math import hypot
import math
class Vector:
@@ -41,7 +41,7 @@ class Vector:
return f'Vector({self.x!r}, {self.y!r})'
def __abs__(self):
return hypot(self.x, self.y)
return math.hypot(self.x, self.y)
def __bool__(self):
return bool(abs(self))