题目

定义坐标点或使用二维坐标数值,计算并输出平面上两点间的欧几里得距离,结果保留两位小数。

输入格式:一行输入 4 个浮点数 x1 y1 x2 y2,以空格分隔。

输出格式:输出两点间欧氏距离,保留两位小数,末尾换行。

数据范围与约定:坐标均为标准浮点数。

思路与算法

1. 欧几里得距离公式
两点间距离为 √( (x1 - x2)² + (y1 - y2)² )。

2. math.hypot
Python 内置 math.hypot(dx, dy) 直接计算欧几里得距离,精度高且避免中间平方溢出。

完整程序

import math

x1, y1, x2, y2 = map(float, input().split())

# math.hypot 计算欧几里得距离,避免中间乘积溢出
dist = math.hypot(x1 - x2, y1 - y2)
print(f'{dist:.2f}')

运行示例

输入:

0 0 3 4

输出:

5.00