登录网站,浏览更多精彩内容
您需要 登录 才可以下载或查看,没有账号?加入我们
×
081 文件内容乘数字(把一个文件的内容加工后生成另一个文件)
[mw_shl_code=html,false]p081.txt内容如下
x,y
3,5
4,9
6,10
7,11
8,12[/mw_shl_code]
[mw_shl_code=python,false]with open("p081.txt") as fin, open("p081_output.txt", "w") as fout:
for line in fin:
if "x,y" in line:
fout.write(line)
else:
x, y = line.strip().split(",")
x = int(x) * 2
y = int(y) * 2
fout.write(f"{x},{y}\n")[/mw_shl_code]
|