Inherit the two-dimensional points in question 1 and input the two three-dimensional points and output the sum. (Be sure to use the method.)
x of 1 //point 1 2 // point 1 y 3 //z
at point 1x of 4 //point 2 5 // point 2 y 6 //z
of point 2579 // Output result
That's the question. The first question was correct, and the code is as follows.
(The first problem was to receive four points and output the sum of two points in two dimensions)
class dot:
x=0
y=0
def __init__(self, _x=0, _y=0):
self.x = _x
self.y = _y
def __add__(self, other):
return str(self.x+other.x)+' '+str(self.y+other.y)
if __name__ == "__main__":
l1=[]
for i in range(4):
l1.append(int(input()))
dot1 = dot(l1[0],l1[1])
dot2 = dot(l1[2],l1[3])
print(dot1+dot2)
I saved this code as a1.py and wrote the code below to solve the problem.
import a1
class dot3d(a1.dot):
z=0
def __init__(self, _z=0):
super().__init__()
self.z = _z
def __add__(self, other):
return str(self.x + other.x) + ' ' + str(self.y + other.y)+' '+str(self.z+other.z)
l1=[]
for i in range(6):
l1.append(int(input()))
dot1 = dot3d(l1[0],l1[1],l1[2])
dot2 = dot3d(l1[3],l1[4],l1[5])
print(dot1+dot2)
When I turned this code and gave 6 inputs, 4 inputs came in, and I sent an error that it was too much.
I think the generator made a mistake in overloading, so can you tell me which part is wrong?
I'm asking you this question because I can't understand even if I search for it.
python
http://blog.naver.com/PostView.nhn?blogId=dudwo567890&logNo=130164649281 I've referred here for an answer.
class dot3d(a1.dot):
def __init__(self, _x, _y, _z=0):
a1.dot.__init__(self, _x, _y)
self.z = _z
© 2024 OneMinuteCode. All rights reserved.