Hi,
I'l trying to use oop, but some stufs remain still unclear for me, both in practice and in "thinking" oop.
The following test is quite basic on the principle, but I do not understand what's wrong (it highlights i've not figured out some topics
Thanks for any advice
I'l trying to use oop, but some stufs remain still unclear for me, both in practice and in "thinking" oop.
The following test is quite basic on the principle, but I do not understand what's wrong (it highlights i've not figured out some topics
- bad use of inheritance?
- wrong snippet?
Thanks for any advice
# -*- coding: utf-8 -*-
import math, os
###
class Point:
# constructor
def __init__(self, num:int = 0,
x:float = 0.,
y:float = 0.,
z:float = 0.,
tol:float = 0.01) :
self._num = num
self._x = x
self._y = y
self._z = z
self._tol = tol
###
def IncrementNum(self):
'''
Method to increment the point number
(internally used)
'''
self._num += 1
###
def GetNum(self):
"""
methode to get the point number
"""
return self._num
###
def GetCoordinates(self):
"""
methode to get the point coordinates
"""
return [self._x, self._y, self._z]
###
class Vector(Point):
## constructor
def __init__(self, num:int = 0,
x:float = 0.,
y:float = 0.,
z:float = 0.,
tol:float = 0.01) :
super().__init__(num, x, y, z, tol)
###
def Calculate(self, other_self):
'''
Method to calculate the vector coordinates using pt1-pt2 instances
write coordinates components in self
'''
self._vector = [(other_self._x - self._x), (other_self._y - self._y), (other_self._z - self._z)]
###
def GetCoordinates(self, other_self) -> list:
'''
Method to get the vector coordinates
return: list (coordinates components)
'''
if not '_vector' in self.__dict__:
vect = Vector.Calculate(self, other_self)
else:
vect = [self._x, self._y, self._z]
return vect
###
def Norm() -> float:
'''
Method to calculate the norm of the vector
Returns: norm (float)
'''
vect = Vector.GetCoordinates()
vect_x = vect[0]
vect_y = vect[1]
vect_z = vect[2]
return math.sqrt(vect_x**2 + vect_y**2 +vect_z**2)
if __name__ == "__main__":
num_pt = 1
pt1 = Point(num = num_pt,
x = 1.5,
y = 0.1,
z = -0.2)
num_pt = pt1.GetNum()
pt2 = Point(num = num_pt,
x = 1.,
y = 0.,
z = 0.)
vect = Vector()
coord = vect.GetCoordinates(pt1, pt2)
# norm = Vector.Norm()
# print(f"... vector = {vect.__dict__}")
# coord = Vector.GetCoordinates(pt1, pt2)Error:TypeError: Vector.GetCoordinates() takes 2 positional arguments but 3 were given
