楼主: lobster_future
760 0

[程序分享] 求助 刚刚发了求助帖 但是问题发生了变化 [推广有奖]

  • 1关注
  • 0粉丝

已卖:1份资源

本科生

84%

还不是VIP/贵宾

-

威望
0
论坛币
96 个
通用积分
0
学术水平
0 点
热心指数
1 点
信用等级
5 点
经验
803 点
帖子
131
精华
0
在线时间
24 小时
注册时间
2017-1-15
最后登录
2018-4-13

楼主
lobster_future 发表于 2017-6-9 15:58:48 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
任务要求 打开一个文本 将所有含有 ADJECTIVE, NOUN, ADVERB OR VERB的地方,请用户输入一个ADJECTIVE, NOUN, ADVERB OR VERB,并填充文本,并且将由用户改过的文本输出并保存到一个新的文本
但是现在在copytext当中 符合正则表达式的格式的文字没有被取代,该怎么办???




#!python3
#madLibs - to attempt the user to type in adjective, noun, adverb and
#verb to replace the ADJECTIVE, NOUN, ADVERB OR VERB

import os,re,pyperclip
##open the text
#suppose there is a text named madLibs.txt
mad=open('madLibs.txt','r')
content=mad.readlines()
copytext=content
##find whether these specific words exist or not
typeRegex=re.compile(r'ADJECTIVE|ADVERB|NOUN|VERB',re.I)
##We need to run the loop through every sentence of the text
for i in range(len(content)):
    for j in range(len(typeRegex.findall(content))):
        ##we want to get every word that we need to substitute
        print('Enter an %s:'%(str(typeRegex.findall(content)[j])).lower())
        temp=str(input())
        print(temp)
        ##substitute with the word that user input
        typeRegex.sub(r'%s'%(temp),copytext)
        print(copytext)
    print(copytext)
##Now we get a list of sentences with the words substituting to the input of user
madLibsNew=open('madLibsNew','w')
madLibsNew.write('This is the new text that some adjectives,adverbs, verbs and nouns that has been substitute from madLabs.txt')
madLibsNew.close()
for i in range(len(copytext)):
    madLibsNew=open('madLibsNew','a')
    madLibsNew.write(copytext)
    print(copytext)
    madLibsNew.close()






二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:求助帖 substitute Sentences Sentence Specific

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-9 09:25