输入平面上两个点a b的坐标计算输出两点间的距离的代码
时间: 2023-05-22 18:01:18 浏览: 132
可以使用以下代码计算两点间的距离:
```python
import math
def distance(a, b):
return math.sqrt((b[0]-a[0])**2 + (b[1]-a[1])**2)
# 示例
a = (1, 2)
b = (4, 6)
print(distance(a, b)) # 输出 5.0
```
这段代码使用了勾股定理计算两点间的距离,其中 `math.sqrt()` 函数用于计算平方根。
阅读全文
相关推荐
![java](https://img-home.csdnimg.cn/images/20250102104920.png)
![java](https://img-home.csdnimg.cn/images/20250102104920.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![ppt](https://img-home.csdnimg.cn/images/20241231044937.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![text/x-c](https://img-home.csdnimg.cn/images/20250102104920.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)