题解 | #重载运算#

重载运算

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

class Coordinate:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, other):
        return Coordinate(self.x + other.x, self.y + other.y)


xy_1 = input()
xy_2 = input()

x_1, y_1 = map(int, xy_1.split())
x_2, y_2 = map(int, xy_2.split())

c1 = Coordinate(x_1, y_1)
c2 = Coordinate(x_2, y_2)

c = c1 + c2
print(f"({c.x}, {c.y})")

全部评论

相关推荐

仁者伍敌:难怪小公司那么挑剔,让你们这些大佬把位置拿了
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-21 13:41
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务