大哥大姐们,这这这这是咋个回事,完全不明白这个输出的格式不一样 ,这个是python入门到实践40招的第100题
具体代码如下
class Coordinate:
def __init__(self,x,y):
self.x = x
self.y = y
def __str__(self):
return f"({self.x},{self.y})"
def __add__(self,other):
if isinstance(other,Coordinate):
new_x = self.x + other.x
new_y = self.y + other.y
return Coordinate(new_x,new_y)
else:
raise TypeError("只能与Coordinate类实例相加")
if __name__ =='__main__':
try:
x1,y1 = map(int,input().split())
x2,y2 = map(int,input().split())
c1 =Coordinate(x1,y1)
c2 =Coordinate(x2,y2)
c3 = c1+c2
print(c3)
except:
print('请输入整数')
具体代码如下
class Coordinate:
def __init__(self,x,y):
self.x = x
self.y = y
def __str__(self):
return f"({self.x},{self.y})"
def __add__(self,other):
if isinstance(other,Coordinate):
new_x = self.x + other.x
new_y = self.y + other.y
return Coordinate(new_x,new_y)
else:
raise TypeError("只能与Coordinate类实例相加")
if __name__ =='__main__':
try:
x1,y1 = map(int,input().split())
x2,y2 = map(int,input().split())
c1 =Coordinate(x1,y1)
c2 =Coordinate(x2,y2)
c3 = c1+c2
print(c3)
except:
print('请输入整数')
全部评论
相关推荐
01-16 11:50
浙江工商大学 Java 点赞 评论 收藏
分享
