【发布时间】:2013-10-31 23:13:47
【问题描述】:
试图得到它,以便它接受输入的特定单词出现在原始字符串中的相同次数,并将其替换为输入的每个单词。
def replace_parts_of_speech (replaced, part_of_speech):
'''Finds and replaces parts of speech with words '''
new_line=''
for i in range (replaced.count(part_of_speech)):
new=input('Enter '+ part_of_speech +':')
new_line = replaced.replace(part_of_speech,new,1)
return new_line
【问题讨论】:
-
这是给 Mad Libs 的,是吗?您能否发布示例输入以及您期望的输出是什么?
-
replace_parts_of_speech ('noun in noun verb', 'noun') Enter noun= 1 Enter noun= 2 预期:'1 in 2 verb' 得到:'2 in noun verb'
-
将预期输出添加到您的问题而不是 cmets
标签: python string loops python-3.x