【发布时间】:2021-02-02 14:17:49
【问题描述】:
我有这段代码的数据结果
import os
with open('c.txt', 'r', encoding='utf-8') as f1, open('c.txt', 'r', encoding='utf-8') as f2, open('r.txt', 'w', encoding='utf-8') as outfile:
for i, line in enumerate(f1):
xi, yi = (float(n) for n in line.split())
f2.seek(0)
for j, line in enumerate(f2):
if i < j:
xj, yj = (float(n) for n in line.split())
print( ((xi-xj)**2-(yi-yj)**2), file=outfile)
print(((xi)**2-(yi)**2), file=outfile)
这段代码应该给我计算,但每次计算时都需要打印 x 和 y 的位置
1 2 0.5
1 3 0.55
1 4 2.02
等等。我试图编写代码,但无法合并我想要的概念。我想我需要编写这段代码来获取值的位置并打印出来
for pos in range(len(f1)):
cor = t[pos]
f.write(str(pos) + ' ' + str(cor[0]) + ' ' + values + '\n')
但无法合并它
c.txt 样例
9.2 2.02
-2.3 1.5
【问题讨论】:
-
这能回答你的问题吗? Print multiple arguments in Python
-
不,我需要的逻辑不同。谢谢
-
你能分享来自
c.txt的样本数据吗? -
当前输出是多少?
-
@yudhiesh 我无法将我需要的概念与我的代码合并
标签: python