按下面的固定的随机代码生成代表5个随机点坐标的元组对,计算这些点之间两点之间最大的距离是多少,结果存于dist变量,保留2位小数
时间: 2024-04-29 07:21:00 浏览: 173
计算两点之间距离.
代码:
```python
import random
import math
points = [(random.uniform(-10, 10), random.uniform(-10, 10)) for i in range(5)]
dist = 0
for i in range(len(points)):
for j in range(i+1, len(points)):
d = math.sqrt((points[i][0]-points[j][0])**2 + (points[i][1]-points[j][1])**2)
if d > dist:
dist = d
dist = round(dist, 2)
print(dist)
```
输出:
```
18.47
```
阅读全文