题解 | #重载运算#

重载运算

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


class Coordinate():
    def __init__(selfxy) -> None:
        self.x = x
        self.y = y
    
    def __str__(self) -> str:
        print(f'({self.x}{self.y})')
        return self.x, self.y

def __add__(c1c2):
    x = c1.x + c2.x
    y = c1.y + c2.y
    newC = Coordinate(x, y)
    return newC

x1, y1 = input().split(' ')
x2, y2 = input().split(' ')
x1 = int(x1)
x2 = int(x2)
y1 = int(y1)
y2 = int(y2)
c1 = Coordinate(x1, y1)
c2 = Coordinate(x2, y2)
c3 = __add__(c1, c2)
c3.__str__()

全部评论

相关推荐

把实习生当正职使昨天第一天就加班,晚上连口饭都没吃上,以后日子咋过,我不想干了
码农索隆:实习不怕忙,就怕干的活重复且没难度,要干就干那种有深度有难度的任务,这样才能快速的提升
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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