python学习笔记:100题记录

[复制链接]
查看1238 | 回复0 | 2024-3-10 08:22:00 | 显示全部楼层 |阅读模式

登录网站,浏览更多精彩内容

您需要 登录 才可以下载或查看,没有账号?加入我们

×
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]





中国领先的数字技术资源交流中心!

30

主题

9

回帖

254

积分

学徒

积分
254
学费
200