Created
April 7, 2022 08:00
-
-
Save timolesterhuis/59f28c55ecba0da2d073348789b0ad9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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