w1w 发表于 2018-8-11 07:17:07

《Python编程快速上手》第8.9.2实践练习

#!python3  #-*- coding:utf-8 -*-
  #8.9.2疯狂填词游戏
  #用户自定义词语,修改打开文件中的ADJECTIVE、NOUN、VERB
  import re
  f=open('first.txt','r+')
  files=f.read()
  print(files)
  f.close()
  changelist=['ADJECTIVE','NOUN','VERB']
  for i in changelist:
  change_reg=re.compile(r'%s' % i)
  text=input("Enter a %s :" % i)
  files=change_reg.sub(text,files)
  fi_2=open('third.txt','w')
  fi_2.write(files)
  fi_2.close()
页: [1]
查看完整版本: 《Python编程快速上手》第8.9.2实践练习