题解 | #重载运算#

重载运算

https://www.nowcoder.com/practice/342d1b8b0fe3416797bad62d22cbb51a

class Coordinate:
    def __init__(self, a, b):
        self.a = a
        self.b = b

    def __str__(self):
        return '(%s, %s)' % (self.a, self.b)

    def __add__(self, other):
        return Coordinate(self.a + other.a, self.b + other.b)


x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
c1 = Coordinate(x[0], x[1])
c2 = Coordinate(y[0], y[1])
print(c1 + c2)

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务