夨完夳一夬计算夲点间夰夦的夯序。 如: Enter point A(x, y):1,1 Enter point B(x, y):2,1 The distance between the pointA and the pointB is 1.0 .
时间: 2023-06-23 18:10:01 浏览: 144
计算两点之间距离.
好的,下面是 Python 代码实现:
```python
import math
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def distance(point1, point2):
return math.sqrt((point1.x - point2.x) ** 2 + (point1.y - point2.y) ** 2)
pointA = Point(*map(int, input("Enter point A(x, y):").split(",")))
pointB = Point(*map(int, input("Enter point B(x, y):").split(",")))
print("The distance between the pointA and the pointB is", distance(pointA, pointB), ".")
```
运行示例:
```
Enter point A(x, y):1,1
Enter point B(x, y):2,1
The distance between the pointA and the pointB is 1.0 .
```
阅读全文