从文件“input.txt”中读入数据(一组二维坐标(x,y)),文件格式如下: 34.1 45,44 -323.67 493.56 42.55 -89.22 34.11 99.56 ……
时间: 2024-01-18 11:04:58 浏览: 32
好的,你可以使用以下 Python 代码来读取“input.txt”文件中的数据:
```python
with open('input.txt', 'r') as f:
data = f.read().split()
coordinates = []
for i in range(0, len(data), 2):
x = float(data[i])
y = float(data[i+1])
coordinates.append((x, y))
```
这个代码将文件中的数据读取到列表 `coordinates` 中,并将每个坐标表示为一个元组 `(x, y)`。现在你可以使用 `coordinates` 列表来进行后续处理。