參考鏈接: Python中的運算符重載
alist = input().split()
?
blist = input().split()
?
n = float(input())
?
?
class Vector:
? ? def __init__(self, x=0, y=0, z=0):
? ? ? ? # 請在此編寫你的代碼(可刪除pass語句)
? ? ? ? self.X = x
? ? ? ? self.Y = y
? ? ? ? self.Z = z
?
? ? ? ? # 代碼結束
?
? ? def __add__(self, other):
?
? ? ? ? return Vector(self.X + other.X, self.Y + other.Y, self.Z + other.Z)
?
?
? ? ? ? # 代碼結束
?
? ? def __sub__(self, other):
?
? ? ? ? return Vector(self.X - other.X, self.Y - other.Y, self.Z -other.Z)
?
?
?
?
? ? ? ? # 代碼結束
?
? ? def __mul__(self, other):
?
? ? ? ? return Vector(self.X * other, self.Y * other, self.Z * other)
? ? ? ? # 請在此編寫你的代碼(可刪除pass語句)
?
?
?
? ? ? ? # 代碼結束
?
? ? def __truediv__(self, other):
?
? ? ? ? return Vector(self.X / other, self.Y / other, self.Z / other)
? ? ? ? # 請在此編寫你的代碼(可刪除pass語句)
?
?
?
?
?
? ? ? ? # 代碼結束
?
? ? def __str__(self):
? ? ? ? # 請在此編寫你的代碼(可刪除pass語句)
? ? ? ? return '(%.1f,%.1f,%.1f)' % (self.X, self.Y, self.Z)
?
?
?
?
?
?
?
?
a = Vector(float(alist[0]), float(alist[1]), float(alist[2]))
?
b = Vector(float(blist[0]), float(blist[1]), float(blist[2]))
?
print(a + b, a - b, a * n, a / n)