我是新手。谁能帮我。
class Triangle():
def __init__(self, a, b, c):
"""
Constructor for Vec4
Expects points as arrays in the form of [x, y].
All coordinates are given as cartesian coordinates.
"""
self.a = a
self.b = b
self.c = c
def __str__(self):
"""
Returns a string representation of the triangle. The string is formatted as follows:
Point A: 0.00 0.00
Point B: 0.00 0.00
Point C: 0.00 0.00
"""
return ""
class Triangle():
def __init__(self, a, b, c):
"""
Constructor for Vec4
Expects points as arrays in the form of [x, y].
All coordinates are given as cartesian coordinates.
"""
self.a = a
self.b = b
self.c = c
def __str__(self):
"""
Returns a string representation of the triangle. The string is formatted as follows:
Point A: 0.00 0.00
Point B: 0.00 0.00
Point C: 0.00 0.00
"""
return "Point A: " + str(self.a[0]) + " " + str(self.a[1]) + "\nPoint B: " + str(self.b[0]) + " " + str(self.b[1]) + "\nPoint C: " + str(self.c[0]) + " " + str(self.c[1])
t = Triangle([5,4], [1,2], [7,9])
print(t)
输出:
Point A: 5 4 Point B: 1 2 Point C: 7 9
这里是代码:
class Triangle():
def __init__(self, a, b, c):
"""
Constructor for Vec4
Expects points as arrays in the form of [x, y].
All coordinates are given as cartesian coordinates.
"""
self.a = a
self.b = b
self.c = c
def __str__(self):
"""
Returns a string representation of the triangle. The string is formatted as follows:
Point A: 0.00 0.00
Point B: 0.00 0.00
Point C: 0.00 0.00
"""
return f"Point A: {self.a[0]} {self.a[1]}\nPoint B: {self.b[0]} {self.b[1]}\nPoint C: {self.c[0]} {self.c[1]}"
您可以使用以下方法来检查:
t = Triangle((2.34,4.62), (6.7,8.52), (9.34,3.32)) print(t)