最新消息:XAMPP默认安装之后是很不安全的,我们只需要点击左方菜单的 "安全"选项,按照向导操作即可完成安全设置。

Python print 输出到文件

XAMPP下载 admin 663浏览 0评论

Python3.x

 

  1. #!/usr/bin/env python3
  2. #coding:utf-8
  3. year = 1
  4. years = 5
  5. bj = 10000
  6. rate = 0.05
  7. f = open(“./source/interest.bak”, ‘w+’)
  8. while year < years:
  9. bj = bj * (1 + rate)
  10. print(“第{0}年,本金息总计{1}”.format(year, bj), file=f)
  11. year += 1

Python2.x

 

  1. #!/usr/bin/env python
  2. #coding:utf-8
  3. year = 1
  4. years = 15
  5. bj = 10000
  6. rate = 0.05
  7. f = open(“./source/interest.bak”, ‘w+’)
  8. while year < years:
  9. bj = bj * (1 + rate)
  10. print >> f, “第%d年,本金息总计%0.2f” % (year, bj)
  11. year += 1
  12.  

转载请注明:XAMPP中文组官网 » Python print 输出到文件

您必须 登录 才能发表评论!