Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions flash_cards.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import random
from vector2d import Vector2d
def print_conversion(vector, str):
if str == "polar":
print(40 * "-")
print(f"Convert {vector.x}i + {vector.y}j to polar form")
print(40 * "-")
elif str == "rectangular":
print(40 * "-")
print(f"Convert <{abs(vector)}, {vector.angle()}> to rectangular form")
print(40 * "-")

def print_polar_conversion(vector):
print(40 * "-")
print(f"Convert {vector.x}i + {vector.y}j to polar form")
print(40 * "-")

def print_rectangular_conversion(vector):
print(40 * "-")
print(f"Convert <{abs(vector)}, {vector.angle()}> to rectangular form")
print(40 * "-")

def generate_vector():
random_x = random.randint(-20,21)
random_y = random.randint(-20,21)
return Vector2d(random_x, random_y)

def print_conversion_solution(vector, str):
if str == "polar":
print(f"<{abs(vector)}, {vector.angle()}>")
elif str == "rectangular":
print(f"{vector.x}i + {vector.y}j")

def print_polar_conversion_solution(vector):
print(f"<{abs(vector)}, {vector.angle()}>")

def print_rectangular_conversion_solution(vector):
print(f"{vector.x}i + {vector.y}j")

if __name__ == '__main__':
while True:
question = input("Would you like to practice polar or rectangular form?")
generated_vector = generate_vector()
if question == "polar":
input(f"{print_polar_conversion(generated_vector)} \n Your answer here ->")
input(f"Correct answer: {print_polar_conversion_solution} \n Press c to continue and press q to quit")

# But don't forget to break at the right time!
break
30 changes: 30 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import math
class Vector2d:
def __init__(self, x, y):
self.x = x
self.y = y
def __repr__(self):
return Vector2d(self.x, self.y)
def __str__(self):
return f"{self.x}i + {self.y}j"
def __abs__(self):
c = self.x ** 2 + self.y ** 2
return c ** (1/2)
def __neg__(self):
return Vector2d(self.x * -1, self.y * -1)
def __add__(self, other):
sum_x = self.x + other.x
sum_y = self.y + other.y
return Vector2d(sum_x,sum_y)
def __eq__(self, other):
if self.x == other.x and self.y == other.y:
return True
def __sub__(self, other):
dif_x = self.x - other.x
dif_y = self.y - other.y
return Vector2d(dif_x, dif_y)
def angle(self):
return math.degrees(math.atan2(self.y, self.x))

test = Vector2d(3,4)
test1 = Vector2d(1,1)
6 changes: 4 additions & 2 deletions vector2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __str__(self):
return f"{self.x}i + {self.y}j"

def __abs__(self):
return (self.x ** 2 + self.y ** 2) ** .5
return round((self.x ** 2 + self.y ** 2) ** .5, 1)

def __neg__(self):
return Vector2d(-self.x, -self.y)
Expand All @@ -27,4 +27,6 @@ def __sub__(self, other):
return Vector2d(self.x - other.x, self.y - other.y)

def angle(self):
return math.degrees(math.atan2(self.y, self.x))
return round(math.degrees(math.atan2(self.y, self.x)), 1)

test = Vector2d(3, 4)