Skip to content

Instantly share code, notes, and snippets.

@timolesterhuis
Created April 7, 2022 08:00
Show Gist options
  • Save timolesterhuis/59f28c55ecba0da2d073348789b0ad9e to your computer and use it in GitHub Desktop.
Save timolesterhuis/59f28c55ecba0da2d073348789b0ad9e to your computer and use it in GitHub Desktop.
import math # We'll use the math module later in this snippet
class Vector:
"""A 2D vector class with some useful methods"""
def __init__(self, x: float, y: float) -> None:
self.x = x
self.y = y
def length(self):
"""a^2 + b^2 = c^2 --> c = sqrt(a^2 + b^2)"""
return math.sqrt(self.x ** 2 + self.y ** 2)
if __name__ == "__main__":
v = Vector(3, 4)
print(type(v))
print(v.length())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment